0

我想在 react-native-maps-markers 中将图像添加到我的调用组件中。但它只显示空矩形。我怎样才能解决这个问题?无需将图像组件放入 Text 组件中。因为那样更难对齐图像。

    return (
        <View style={styles.container} >
        <MapView
         
         Provider= {PROVIDER_GOOGLE}
         ref={map => this._map = map}
         showsUserLocation={true}
         style={styles.map}
         initialRegion={this.state.initialPosition}
         customMapStyle={mapStyle}>

            {
                this.state.coordinates.map((marker, index) => (
                    <Marker
                    key={marker.name}
                    ref={ref => this.state.markers[index] = ref}
                    //onPress={() => this.onMarkerPressed(marker, index)}
                    coordinate={{latitude: marker.latitude, longitude: marker.longitude}}
                    title={'Safe Parking'}>
                    
                    <Image 
                    source={require('../icons/park.jpg')}
                    style={styles.icon}/>
                    <Callout>
                        <Image 
                        source={marker.image}
                        style={styles.image}
                        />  
                    </Callout>        
                    </Marker>
                ))
            }

       </MapView>
       
       </View>
    );
}
};
4

1 回答 1

0

您是否为图像设置了高度和宽度?

如果是,请尝试导入您的图像,而不是像这样

import parkIcon from '../icons/park.jpg'

<Image source={parkIcon}
于 2020-07-27T07:45:24.940 回答