저는 사용자 위치를 검색하고 가장 가까운 위치의 목록을 정렬하기 위해 기본 Geolocation 플러그인과 함께 Ionic을 사용하고 있습니다. Geolocation 플러그인은 iOS 기기는 물론 ionic serve
또는 ionic lab
을 사용하여 완벽하게 작동하지만 Android 기기 (시뮬레이터)에서는 작동하지 않습니다.Native IONIC Geolocation이 Android 장치에서 작동하지 않습니다.
사용자의 경도와 위도를 검색하는 데 사용할 수있는 다른 해결책은 무엇입니까?
여기에 Geolocation 플러그인을 사용하는 클래스를 연결합니다.
위치 클래스 나는 더 많은 클래스에서 수정 될 것이므로 userLocation을 저장하는 public static 변수가 있습니다.
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');
}
}