爱奥尼亚:地理定位在Android上不起作用

爱奥尼亚:地理定位在Android上不起作用,android,cordova,geolocation,ionic-framework,cordova-plugins,Android,Cordova,Geolocation,Ionic Framework,Cordova Plugins,情况: var options = { timeout: 10000, enableHighAccuracy: true }; $cordovaGeolocation.getCurrentPosition(options).then(function(position) { $scope.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); $sc

情况:

var options = { timeout: 10000, enableHighAccuracy: true };

$cordovaGeolocation.getCurrentPosition(options).then(function(position)
{
    $scope.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    $scope.map.markers = [{
        id: "first",
        location_data: {
        latitude: 45.3694868,
        longitude: -73.9803275
        }
    },{
        id: "second",
        icon: "img/blue_marker.png",
        location_data: {
        latitude: $scope.userLocation.H,
        longitude: $scope.userLocation.L
        }
    }];

}, function(error){

    alert('error geolocation');


});
k: no valid models attribute found 

TypeError: Cannot read property 'length' of undefined
at k.didQueueInitPromise 

TypeError: Cannot read property 'gManager' of undefined
at Object.fn 

TypeError: Cannot read property 'length' of undefined
at Object.fn

PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
我正在用Ionic框架构建一个混合应用程序。我需要获取用户位置

我发现了一个叫cordova的插件

它在浏览器中工作得很好,但在手机(Android)或模拟器(Genymotion)中测试应用程序却不起作用

我知道在这方面也有类似的问题,但解决方案对我不起作用

代码:

var options = { timeout: 10000, enableHighAccuracy: true };

$cordovaGeolocation.getCurrentPosition(options).then(function(position)
{
    $scope.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    $scope.map.markers = [{
        id: "first",
        location_data: {
        latitude: 45.3694868,
        longitude: -73.9803275
        }
    },{
        id: "second",
        icon: "img/blue_marker.png",
        location_data: {
        latitude: $scope.userLocation.H,
        longitude: $scope.userLocation.L
        }
    }];

}, function(error){

    alert('error geolocation');


});
k: no valid models attribute found 

TypeError: Cannot read property 'length' of undefined
at k.didQueueInitPromise 

TypeError: Cannot read property 'gManager' of undefined
at Object.fn 

TypeError: Cannot read property 'length' of undefined
at Object.fn

PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
控制台中的错误消息:

var options = { timeout: 10000, enableHighAccuracy: true };

$cordovaGeolocation.getCurrentPosition(options).then(function(position)
{
    $scope.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    $scope.map.markers = [{
        id: "first",
        location_data: {
        latitude: 45.3694868,
        longitude: -73.9803275
        }
    },{
        id: "second",
        icon: "img/blue_marker.png",
        location_data: {
        latitude: $scope.userLocation.H,
        longitude: $scope.userLocation.L
        }
    }];

}, function(error){

    alert('error geolocation');


});
k: no valid models attribute found 

TypeError: Cannot read property 'length' of undefined
at k.didQueueInitPromise 

TypeError: Cannot read property 'gManager' of undefined
at Object.fn 

TypeError: Cannot read property 'length' of undefined
at Object.fn

PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
问题:

var options = { timeout: 10000, enableHighAccuracy: true };

$cordovaGeolocation.getCurrentPosition(options).then(function(position)
{
    $scope.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    $scope.map.markers = [{
        id: "first",
        location_data: {
        latitude: 45.3694868,
        longitude: -73.9803275
        }
    },{
        id: "second",
        icon: "img/blue_marker.png",
        location_data: {
        latitude: $scope.userLocation.H,
        longitude: $scope.userLocation.L
        }
    }];

}, function(error){

    alert('error geolocation');


});
k: no valid models attribute found 

TypeError: Cannot read property 'length' of undefined
at k.didQueueInitPromise 

TypeError: Cannot read property 'gManager' of undefined
at Object.fn 

TypeError: Cannot read property 'length' of undefined
at Object.fn

PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
为什么地理定位在浏览器中运行良好,但在安卓上却不行? 确切的原因是什么? 我怎样才能使它正常工作


谢谢

这取决于您的cordova版本。将其“npm更新-g cordova”更新为最新版本。
如果不起作用,请尝试使用此方法navigator.geolocation.getCurrentPosition

这取决于您的cordova版本。将其“npm更新-g cordova”更新为最新版本。
如果不起作用,请尝试使用此方法navigator.geolocation.getCurrentPosition

这取决于您的cordova版本。将其“npm更新-g cordova”更新为最新版本。
如果不起作用,请尝试使用此方法navigator.geolocation.getCurrentPosition

这取决于您的cordova版本。将其“npm更新-g cordova”更新为最新版本。 如果不起作用,请尝试使用此方法navigator.geolocation.getCurrentPosition

试试这个: 请不要写导入语句

添加地理位置## $ionic插件添加cordova插件地理位置

如何使用它 直接和无需进口

Geolocation.getCurrentPosition()。然后((resp)=>{
//各自坐标纬度
//各自坐标经度
})
让watch=Geolocation.watchPosition();
观看。订阅((数据)=>{
//数据坐标纬度
//data.coords.longitude
})
试试这个: 请不要写导入语句

添加地理位置## $ionic插件添加cordova插件地理位置

如何使用它 直接和无需进口

Geolocation.getCurrentPosition()。然后((resp)=>{
//各自坐标纬度
//各自坐标经度
})
让watch=Geolocation.watchPosition();
观看。订阅((数据)=>{
//数据坐标纬度
//data.coords.longitude
})
试试这个: 请不要写导入语句

添加地理位置## $ionic插件添加cordova插件地理位置

如何使用它 直接和无需进口

Geolocation.getCurrentPosition()。然后((resp)=>{
//各自坐标纬度
//各自坐标经度
})
让watch=Geolocation.watchPosition();
观看。订阅((数据)=>{
//数据坐标纬度
//data.coords.longitude
})
试试这个: 请不要写导入语句

添加地理位置## $ionic插件添加cordova插件地理位置

如何使用它 直接和无需进口

Geolocation.getCurrentPosition()。然后((resp)=>{
//各自坐标纬度
//各自坐标经度
})
让watch=Geolocation.watchPosition();
观看。订阅((数据)=>{
//数据坐标纬度
//data.coords.longitude

})
我在使用cordova地理定位插件

navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
我也面临着同样的问题,它在genymotion中不起作用。将enableHighAccurance设置为true对我的作用如下

var options = {
  enableHighAccuracy: true,
  maximumAge: 0
};

我使用的是cordova地理定位插件

navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
我也面临着同样的问题,它在genymotion中不起作用。将enableHighAccurance设置为true对我的作用如下

var options = {
  enableHighAccuracy: true,
  maximumAge: 0
};

我使用的是cordova地理定位插件

navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
我也面临着同样的问题,它在genymotion中不起作用。将enableHighAccurance设置为true对我的作用如下

var options = {
  enableHighAccuracy: true,
  maximumAge: 0
};

我使用的是cordova地理定位插件

navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
我也面临着同样的问题,它在genymotion中不起作用。将enableHighAccurance设置为true对我的作用如下

var options = {
  enableHighAccuracy: true,
  maximumAge: 0
};


您在AndroidManifest文件中指定了任何权限吗?是的,我已经更新了这个问题。您为什么要谈论
全球化
插件?这与地理位置无关。尝试
console.log
记录错误,查看问题所在,并告诉我们结果。如果将
enableHighAccurance
设置为false,会发生什么情况?对不起,我在问题中进行设置时混淆了它们。全球化是为了多种语言。无论如何,我已经安装了地理定位。情况也是如此。但我编辑了问题,包括控制台中的错误。我只是将其降级到以下环境:Cordova CLI:4.3.1 Ionic Framework版本:1.3.2 Ionic CLI版本:1.7.16 Ionic应用程序库版本:0.7.3 ios部署版本:未安装ios sim版本:未安装OS:Mac OS X El Capitan节点版本:v4.6.1,它可以工作!您在AndroidManifest文件中指定了任何权限吗?是的,我已经更新了这个问题。您为什么要谈论
全球化
插件?这与地理位置无关。尝试
console.log
记录错误,查看问题所在,并告诉我们结果。如果将
enableHighAccurance
设置为false,会发生什么情况?对不起,我在问题中进行设置时混淆了它们。全球化是为了多种语言。无论如何,我已经安装了地理定位。情况也是如此。但我编辑了问题,包括控制台中的错误。我只是将其降级到以下环境:Cordova CLI:4.3.1 Ionic Framework版本:1.3.2 Ionic CLI版本:1.7.16 Ionic应用程序库版本:0.7.3 ios部署版本:未安装ios sim版本:未安装OS:Mac OS X El Capitan节点版本:v4.6.1,它可以工作!您在AndroidManifest文件中指定了任何权限吗?是的,我已经更新了这个问题。您为什么要谈论
全球化
插件?这与地理位置无关。尝试
console.log
记录错误,查看问题所在,并告诉我们结果。如果将
enableHighAccurance
设置为false,会发生什么?那么