ionic 3에서 위치 정보 및 Google지도를 사용하려고하는데 앱이 브라우저에서 제대로 작동합니다.
하지만 어떤 이유에서인지 APK를 빌드 할 때 휴대 전화에지도가 표시되지 않습니다.
이것은 지리적 위치 .ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Geolocation, Geoposition } from '@ionic-native/geolocation';
declare var google;
@IonicPage()
@Component({
selector: 'page-geo',
templateUrl: 'geo.html',
})
export class GeoPage {
map: any;
constructor(public navCtrl: NavController, public navParams: NavParams, public geo: Geolocation) { }
ionViewDidLoad() {
this.getPosition();
}
getPosition():any{
this.geo.getCurrentPosition().then(resp => {
this.loadMap(resp);
}).catch((error) =>{
console.log(error);
})
}
loadMap(position: Geoposition){
let latitud = position.coords.latitude;
let longitud = position.coords.longitude;
console.log(latitud, longitud);
let mapEle: HTMLElement = document.getElementById('map');
let myLatLng = {lat: latitud, lng: longitud};
this.map = new google.maps.Map(mapEle, {
center: myLatLng,
zoom: 12
});
google.maps.event.addListenerOnce(this.map, 'idle', () => {
let marker = new google.maps.Marker({
position: myLatLng,
map: this.map,
title: 'Hello World!'
});
mapEle.classList.add('show-map');
});
}
}
나는 무엇이 잘못되었는지 모르겠다. 조언에 감사한다.
당신의 문제는 loadMap(resp)
성공적으로 지리적 위치를 얻은 후에 만 전화한다는 것 입니다.
지리적 위치 요청이 실패하면 (권한으로 인해) 앱이로드되지 않습니다.
지도를로드 한 다음 중심을 설정해야합니다.
ionViewDidLoad() {
this.loadmap()
this.getPosition();
}
getPosition(): any {
this.geo.getCurrentPosition().then(resp => {
this.setCenter(resp);
}).catch((error) => {
console.log(error);
})
}
loadMap() {
let mapEle: HTMLElement = document.getElementById('map');
this.map = new google.maps.Map(mapEle, {
center: myLatLng,
zoom: 12
});
}
setCenter(position: Geoposition) {
let myLatLng = { lat: position.coords.latitude, lng: position.coords.longitude };
this.map.setCenter(myLatLng);
google.maps.event.addListenerOnce(this.map, 'idle', () => {
let marker = new google.maps.Marker({
position: myLatLng,
map: this.map,
title: 'Hello World!'
});
mapEle.classList.add('show-map');
});
}
또는 지리적 위치 약속을 호출 loadMap()
하고 .catch()
좌표없이지도를로드 할 수 있습니다.
getPosition(): any {
this.geo.getCurrentPosition().then(resp => {
this.loadMap(resp);
}).catch((error) => {
// Load the map even if we fail
this.loadMapFallback();
console.log(error);
});
}
/*
... old load map function
*/
loadMapFallback() {
let mapEle: HTMLElement = document.getElementById('map');
this.map = new google.maps.Map(mapEle, {
zoom: 12
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다