我在我的应用上使用airbnb's map作为react-native。这个问题是为Android应用程序,因为我还没有解决iOS应用程序。在React Native AirBnb的MapView上关注用户位置[Android]
我的问题:
navigator.geolocation正常工作在模拟器,但时间过长在真实设备上,给点有时超时旧设备。
我已经注意到:
如果showsUserLocation
道具设置为true,我可以看到在地图上的方式本土“当前位置”标志之前getCurrentPosition缓解。
我想要什么:
- 我要永远对用户的位置为中心我所在的地区。
- 我想要一种方法来访问本地地理位置api(应该更快?),或者有人告诉我我做错了什么。以下是 的一个代码示例。
- 即使位置服务已打开/关闭,我仍然能够检测到用户的位置。这是
showsUserLocation
道具的行为,但它似乎一旦watchPostion错误,它完全停止。
这里是我到目前为止,这是非常简单的,因为它是:
如果componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("getCurrentPosition Success");
this.setState({
region: {
...this.state.region,
latitude: position.coords.latitude,
longitude: position.coords.longitude,
}
});
this.props.resetNotifications();
this.watchPosition();
},
(error) => {
this.props.displayError("Error dectecting your location");
alert(JSON.stringify(error))
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
}
watchPosition() {
this.watchID = navigator.geolocation.watchPosition(
(position) => {
console.log("watchPosition Success");
if(this.props.followUser){
this.map.animateToRegion(this.newRegion(position.coords.latitude, position.coords.longitude));
}
},
(error) => {
this.props.displayError("Error dectecting your location");
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
}
您应该离开办公室或家中使用设备进行位置测试。在真实设备中必须为'enableHighAccuracy:true'。它对我来说是完美的。 –
检查它这个问题http://stackoverflow.com/a/38125402/2955679 –
@pedropeixoto我做了所有安装指南中要求的,但showsUserLocation不适用于我。你能帮我吗。? – HelpingHand