在 IOS 中查找 GPS 坐标时没有问题。效果很好。
Android 端不如 IOS 稳定。在真机和模拟器中都会出现这个问题。有时它可以找到位置,但有时却找不到。寻找了3天,但没有找到解决方案。
当我的应用程序无法找到我的位置时,我尝试通过谷歌地图应用程序,它就像魅力一样。
这是我针对 IOS 和 Android 的代码;
getCurrentPosition() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({ initialPosition: position });
alert(JSON.stringify(position))
var coords = new Coords();
coords.Latitude = position.coords.latitude;
coords.Longitude = position.coords.longitude;
this.getPharmaciesByCoordinates(coords);
},
(error) => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
this.watchID = navigator.geolocation.watchPosition((position) => {
this.setState({ initialPosition: position });
},
(error) => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
}
欢迎任何类型的解决方案。
Thanks
我删除了maximumAge: 3600000
在 Android 上并且它可以工作
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)