基于纬度经度
问题描述:
我开发样本反应,本地应用程序如何定位到特定的位置,在该应用程序我使用的反应 - 原生地图。它的工作精细地图显示当前位置,但是,我有自定义纬度经度,现在我想要导航到特定的位置,当我点击一个按钮。基于纬度经度
这儿,这是我的代码:
<MapView
ref='map'
style={styles.map}
region={this.state.mapRegion}
showsUserLocation={true}
followUserLocation={true}
zoomEnabled={true}
pitchEnabled={true}
showsCompass={true}
showsBuildings={true}
showsTraffic={true}
showsIndoors={true}
onRegionChange={this.onRegionChange.bind(this)}
onPress={this.onMapPress.bind(this)}>
{this.state.markers.length != 0 || this.state.markers != undefined ?(
this.state.markers.map(marker => (
<MapView.Marker
coordinate={{
latitude: marker.Latitude||this.state.lastLat||region.latitude,
longitude:marker.Longitude||this.state.lastLong||region.longitude
}}
image = {
marker.EmergencyService == true ?(
require('./Imgs/emergencyService.png')):
(require('./Imgs/regularService.png'))
}
onCalloutPress={() => this.bookDoctorsAppointment(marker)}
>
<MyCustomMarkerView marker={marker} navigator={this.props.navigator}/>
</MapView.Marker>
)
)):(<View></View>)}
</MapView>
答
似乎有可用一堆的方法,我尝试animateToRegion
如下:
https://github.com/airbnb/react-native-maps/blob/master/docs/mapview.md#methods
所以使用REF尝试
class MyComp extends Component {
setMap =() => {
if (this.map) {
console.log('keys on this.map:', Object.keys(this.map));
this.map.animateToRegion(...);
}
}
getRefMap = el => this.map = el; // this also triggers when <MapView unmounts but el will be `null` so you can test if (el) { alert('mounted') } else { alert('unmounted') }
render() {
return (
<View>
<Text onPress={this.setMap}>Set map!</Text>
<MapView ref={this.getRefMap} ...>;
</View>
)
}
}
我没有得到你能解释一下这个 – Lavaraju
原谅我请,我不擅长英语,我可以写,但我的理解能力和表达能力很差。 @Lavaraju给你的组件附加'ref',然后你可以在ref实例中看到这些方法。 – ystal