React Native Maps: Markers image doesn't show using Custom Marker in react-native-maps

后端 未结 10 1821
别那么骄傲
别那么骄傲 2021-02-05 16:52

I\'m using react-native-maps but I faced a problem that after a lot of googling without answer makes me ask it here. I\'m trying to use Custom Marker for the marker

相关标签:
10条回答
  • 2021-02-05 17:24

    Use SVG for this https://github.com/react-native-community/react-native-svg

    <Marker
        coordinate={{
            longitude: lang,
            latitude: lat,
        }}
    >
        <View style={{
            flexDirection: 'row', width: 100, height: 30,
            backgroundColor: 'orange'
        }}>
            <Svg
                width={40} height={30}>
                <Image
                    href={url}
                    width={40}
                    height={30}
                />
            </Svg>
            <View
                style={{
                    flexDirection: 'column'
    
                }}
            >
                <Text
                    style={{
                        marginLeft: 2,
                        fontSize: 9,
                        color: '#ffffff',
                        fontWeight: 'bold',
                        textDecorationLine: 'underline'
                    }}
                >{marker.title}</Text>
                <Text
                    style={{
                        marginLeft: 2,
                        fontSize: 9,
                        color: '#ffffff',
                        fontWeight: 'bold',
                        textDecorationLine: 'underline'
                    }}
                >{marker.description}</Text>
            </View>
        </View>
    </Marker>
    
    0 讨论(0)
  • 2021-02-05 17:28

    Add your custom marker component inside <View> e.g. <View> your marker custom view </View>. Maybe it will resolve your issue.

    0 讨论(0)
  • 2021-02-05 17:30

    This is another example

    class PinMarker extends Component {
      state = {
        initialRender: true
      }
      render() {
        return (
          <MapView.Marker coordinate={coordinate}>
            <Image
              source={...}
              onLayout={() => this.setState({ initialRender: false })}
              key={`${this.state.initialRender}`}
            />
          </MapView.Marker>
        )
      }
    }
    
    0 讨论(0)
  • @Mahdi Bashirpour solution works for me. just upgrading above answer.

    Other Images stop working if we import 'Image' from 'react-native-svg'

    My solution is below.

    import {Image} from 'react-native';   // for other images in our render method.
    import { Image as Imagesvg } from 'react-native-svg';
    
    <Marker
       coordinate={marker.latlng}
       title={marker.title}
     >
    
    <View style={{ height: 90, width: 90, backgroundColor: 'orange' }}>
          <Svg width={90} height={90}}>
            <Imagesvg href={marker_g} width={90} height={90} />  // Local Images
           <Imagesvg href={{uri:url}} width={90} height={90} />   //Server images
        </Svg>
    </View>
    </Marker>
    

    Use 'Imagesvg' for marker image. It's working for me on android 7 and 8. React native version '0.55.3'

    0 讨论(0)
提交回复
热议问题