【发布时间】:2018-08-19 07:07:47
【问题描述】:
我正在使用react-native-maps,但我遇到了一个问题,经过大量谷歌搜索而没有答案让我在这里问它。
我正在尝试使用自定义标记作为地图中的标记,如下图所示
-
我在搜索中发现需要使用自定义标记来完成制造商的设计,然后我创建了一个自定义标记组件
import React, { Component } from "react"; import { View } from "react-native"; import { Text, Left, Right, Thumbnail, } from "native-base"; const defaultEmployeeLogo = require("../../../assets/defualtEmployee.png"); class CustomMarker extends Component { render() { return ( <View style={{ flexDirection: 'row', width: 140, height: 60, borderRadius: 70, backgroundColor: 'orange' }}> <Left> <Thumbnail source={defaultEmployeeLogo} /> </Left> <Right> <Text style={{ color: '#fef', fontSize: 13, paddingBottom: 2, fontFamily: 'Roboto', alignItems: 'center', paddingRight: 10 }}>Mohammad</Text> </Right></View >); } } export default CustomMarker;
当我单独使用 CustomMarker.js 类时,它可以正常工作并显示图像,但是当我将其用作标记自定义视图时,它不会显示图像
我不知道为什么它不能在 android 中使用 Custom Marker 渲染图像。 这是我使用地图、标记和自定义标记类的代码
return (
<View style={styles.map_container}>
<MapView
style={styles.map}
customMapStyle={customrMapStyle}
region={{
latitude: this.state.region.latitude,
longitude: this.state.region.longitude,
latitudeDelta: 0.4,
longitudeDelta: 0.41,
}} >
{
coordinationData.map(function (marker, i) {
let lat = marker.latLang.latitude;
let lang = marker.latLang.longitude;
<MapView.Marker
key={i}
coordinate={
{
latitude: lat,
longitude: lang,
latitudeDelta: 0.4,
longitudeDelta: 0.41
}
}
title={marker.title}
description={marker.description}
>
<CustomMarker />
</MapView.Marker>
})}
</MapView>
</View>
我们将不胜感激。
【问题讨论】:
标签: android google-maps react-native react-native-maps