【发布时间】:2018-03-21 06:46:42
【问题描述】:
我将 Ionic 与原生 Geolocation 插件一起使用来检索用户位置并按最接近用户的方式对位置列表进行排序。
Geolocation 插件可以完美地使用ionic serve 或ionic lab 以及iOS 设备,但它不能在Android 设备(或模拟器)上工作。
我可以使用其他什么解决方案来检索用户的经度和纬度?
我将在此处附上我使用 Geolocation 插件的类。
我访问的 Location 类有一个公共静态变量,我在其中存储 userLocation,因为将在更多类中进行修改。
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');
}
}
【问题讨论】:
标签: android ionic-framework geolocation geocoding ionic-native