我在ionic应用程序中使用过$cordovaGeolocation.getCurrentPosition。它能在安卓和网络上正常工作,并能正确获取位置。但在xcode模拟器中,它不能工作,也不能获取经度和纬度。并且不能获取经度和纬度。
var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
$scope.Lat = position.coords.latitude;
$scope.Long = position.coords.longitude;
console.log('lat:', $scope.Lat);
console.log('long:', $scope.Long);
}, function(err) {
console.log(err);
}); 我已将此代码放入.run函数的app.js文件中。
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("corodova.geolocation works well");
}发布于 2017-03-25 17:59:16
在iPhone模拟器中,您可以模拟位置。
您需要转到调试->位置->自定义位置

您还可以在对话框中添加自定义经度,然后按OK。

您还可以从Xcode模拟位置。
为此,您需要运行一个应用程序,在日志区上方,您将看到如下图所示的导航按钮,并从列表中选择城市。

发布于 2017-03-25 17:56:54
模拟器不能自动检测位置。
模拟位置ios模拟器
启动iOS模拟器。然后,打开iOS模拟器的调试菜单并选择位置。
https://stackoverflow.com/questions/43014878
复制相似问题