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');
}
}