Ionic 3:不同Android版本的地理定位不稳定

时间:2018-03-28 05:44:24

标签: ionic-framework geolocation ionic3

我正在开发一个基于地理位置的离子项目,在四个真实设备上测试我的应用程序后,我区分了三种不同的行为:

1) Android 4.x (J1 Samsung)=>正确地工作

2) Android 5.0.1 =>我第一次安装应用程序时所有工作都按预期工作,但是当我禁用GPS并再次启用它时,地理定位返回的位置远远超过我的位置1Km并且它仍然有问题,直到我重新启动电话然后再次正常工作直到我重启了GPS。

3) Android 5.1 => Android 5.0.1的相同情况但在关闭GPS并再次启用它之后,地理定位仍然会返回错误“超时”,直到我重新启动电话。

请,我必须知道是否没有解决方案或者我可以继续使用此插件吗?

  

Home.ts:

import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';

declare const google;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  @ViewChild('map') mapElement: ElementRef;
  map: any;

  constructor(public navCtrl: NavController,
              private platform:Platform,
              private geolocation:Geolocation) {

  }

  ionViewDidLoad(){
    new Promise(resolve => {
      setTimeout(() => {
        this.initMap();
        resolve();
      },2000);
    })
    .then(()=>{
      setTimeout(() => {
        this.getGeolocation();
      },2000);
    });
  }


  initMap() {
    // map implementation
  }

  getGeolocation(){
    this.platform.ready().then(() => {
      alert('start geolocation');
      var options = {
        timeout: 20000,
        enableHighAccuracy:true,
      };

      this.geolocation.getCurrentPosition(options).then(resp => {
        alert('done');
        console.log(resp.coords.latitude);
        console.log(resp.coords.longitude);
        let origin = new google.maps.LatLng( resp.coords.latitude,resp.coords.longitude);
        this.addMarker(origin);  
        this.map.setCenter(origin);
      }).catch((error) => {
        this.debugError(error); 
        alert('error geoloc');
      });

    });
  }

addMarker(location) {
   //addMarker implementation
}

  debugError(object){
    var output = '';
    for (var property in object) {
      output += property + ': ' + object[property]+'; ';
    }
    alert(output);
    console.log(output);
  }
}
  

离子信息:

cli包:(/ usr / lib / node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

全球套餐:

cordova (Cordova CLI) : 7.1.0 

本地包裹:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

系统:

Android SDK Tools : 26.1.1
Node              : v8.9.4
npm               : 5.7.1 
OS                : Linux 4.13

环境变量:

ANDROID_HOME : xxx

其他:

backend : pro

cli包:(/ usr / lib / node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

全球套餐:

cordova (Cordova CLI) : 7.1.0 

本地包裹:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

系统:

Android SDK Tools : 26.1.1
Node              : v8.9.4
npm               : 5.7.1 
OS                : Linux 4.13

环境变量:

ANDROID_HOME: xxx/Sdk

其他:

backend: pro

0 个答案:

没有答案