0
我使用Ionic与原生地理定位插件来检索用户位置并按距离用户最近的顺序对列表进行排序。 地理位置插件可以完美地使用ionic serve
或ionic lab
以及iOS设备,但它不适用于Android设备(也不适用于模拟器)。本机IONIC地理定位不适用于Android设备。
还有什么其他解决方案可以用来检索用户的经度和纬度?
我会在这里附上我使用Geolocation插件的类。
的位置类我访问了那里我存储用户位置,因为将在多个类修改的公共静态变量。
this.Location.load
仅使用用户位置调用Location
类中的方法对地点列表进行排序。
import { Component } from '@angular/core';
import { ModalController, NavController, NavParams } from 'ionic-angular';
import { SharePopup } from '../share-popup/share-popup';
import { InAppBrowser } from 'ionic-native';
import { CamhsPage } from '../camhs-page/camhs-page';
import { Locations } from '../../providers/locations';
import { Platform } from 'ionic-angular';
import { Geolocation } from 'ionic-native';
@Component({
selector: 'contact',
templateUrl: 'contact.html'
})
export class Contact {
userPosition = [0, 0];
constructor(public navCtrl: NavController, public navParams: NavParams,
public modalCtrl: ModalController, public locations: Locations,public platform: Platform) {
}
openCamhsPage(){
this.platform.ready().then(() => {
let options = {
timeout: 10000,
enableHighAccuracy: true
};
Geolocation.getCurrentPosition(options).then((data) => {
Locations.userPosition[0] = Math.round(data.coords.latitude * 100)/100;
Locations.userPosition[1] = Math.round(data.coords.longitude * 100)/100;
// console.log("CONTACT "+Locations.userPosition);
});
});
this.locations.load();
this.navCtrl.push(CamhsPage);
console.log("CONTACT "+Locations.userPosition);
}
//Open WebPage
openPage(url) {
new InAppBrowser(url, '_system');
}
}