简体   繁体   English

地理位置Cordova Android插件不起作用

[英]Geolocation cordova Android plugin does not work

I am developing an application which 70% of it is based on geolocation. 我正在开发一个应用程序,其中70%基于地理位置。 I began to develop in the iOS and everything works great, I had some problems but nothing that is not solvable logically. 我开始在iOS中进行开发,并且一切正常,我遇到了一些问题,但是没有什么在逻辑上无法解决。 Now, I was asked a version for Android, at first impression, everything works identical to iOS, but when the testing version that give me problems arose geolocation. 现在,我被问到一个适用于Android的版本,乍一看,所有功能都与iOS相同,但是当给我带来问题的测试版本出现了地理位置问题。 The problem is that being off the GPS from the phone (I tested Samsung, Xperia, Motorolas) fall into the error function (which I defined) to alert the user that the GPS was off and that should enable it to occupy. 问题在于,从手机上断开GPS(我测试过Samsung,Xperia,Motorolas)时会陷入错误功能(由我定义),以提醒用户GPS处于关闭状态,这应该使它能够被占用。 However, activating it, it does not work well, restart the computer to work correctly recently, I'm crazy, because even I get an error response, or alerts you leave, or anything like that. 但是,激活它并不能很好地工作,最近重新启动计算机就可以正常工作,我很疯狂,因为即使我收到错误响应,或者提醒您离开,等等。

My code : 我的代码:

$scope.$on('$ionicView.enter', function(){
 $(function(){
  document.addEventListener("deviceready", onDeviceReady, false);
 })

 function onDeviceReady() {
  navigator.geolocation.getCurrentPosition(onSuccess, onError);
 }

 function onSuccess(pos) {
  $scope.latitud = pos.coords.latitude
  $scope.longitud =  pos.coords.longitude;
  console.log(pos.coords.latitude);
  $scope.mostrar_cercanos = true;
  $scope.getViews();
 }

 function onError(error) { 
  $scope.mostrar_cercanos = false;
  $scope.mostrar_mensaje_gps = true;
  $scope.mensaje = "El GPS de su telefono no se encuentra activado";
 }
})

Plugins : 外挂程式:

org.apache.cordova.geolocation 0.3.12 "Geolocation"
org.apache.cordova.inappbrowser 0.6.0 "InAppBrowser"
org.apache.cordova.network-information 0.2.15 "Network Information"
org.apache.cordova.splashscreen 1.0.0 "Splashscreen"

I have to go back to iOS mention that everything works as I want. 我必须回到iOS提及一切都可以按我的方式工作。

I would recommend you to use ngcordova . 我建议您使用ngcordova

http://ngcordova.com/docs/plugins/geolocation/ http://ngcordova.com/docs/plugins/geolocation/

I have used this in my application and it worked fine. 我已经在我的应用程序中使用了它,并且效果很好。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM