我正在使用react-native-maps模块。我已经给出了纬度和经度值,并且我使用MapView.Marker在单击标记时显示标记和工具提示。
但是,现在我想在地图最初加载时显示工具提示,而无需单击标记。
这是我的代码:
<View style={styles.page}>
<MapView
ref="map"
style={styles.map}
region={this.state.region}
provider = {PROVIDER_DEFAULT}
zoomEnabled={true}
onRegionChange={this.onRegionChange.bind(this)}
pitchEnabled={true}
showsCompass={true}
liteMode={false}
showsBuildings={true}
showsTraffic={true}
showsIndoors={true}
>
<MapView.Marker
coordinate={this.state.marker.latlng}
title={this.state.marker.title}
description={this.state.marker.description}
image={require('./assets/pin.png')}
/>
</MapView>
</View>
谁能帮忙解决这个问题吗...
我找不到任何关于 MapView 的 onLoad 属性的任何文档,所以我使用 onLayout 作为替代在这里建议 https://github.com/airbnb/react-native-maps/issues/367。您将需要使用显示标注方法 https://github.com/airbnb/react-native-maps/blob/master/docs/marker.md#methods让标记显示工具提示。为此,请为标记添加一个引用,然后您可以在 MapView 的 onLayout 中使用该引用。
<View style={styles.page}>
<MapView
ref="map"
style={styles.map}
region={this.state.region}
provider = {PROVIDER_DEFAULT}
zoomEnabled={true}
onRegionChange={this.onRegionChange.bind(this)}
pitchEnabled={true}
showsCompass={true}
liteMode={false}
showsBuildings={true}
showsTraffic={true}
showsIndoors={true}
onLayout={() => { this.mark.showCallout(); }}
>
<MapView.Marker
ref={ref => { this.mark = ref; }}
coordinate={this.state.marker.latlng}
title={this.state.marker.title}
description={this.state.marker.description}
image={require('./assets/pin.png')}
/>
</MapView>
</View>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)