Why my google map
is not appearing in on android
device.
I'm able console.log(); lat, lang
in browser. device will ask permission for location access but it will not render map
.
below code works fine for predefined lat, lang
ionViewDidLoad() {
console.log('ionViewDidLoad GoogleMapTestPage');
this.loadMapHandler();
}
loadMapHandler() {
//console.log(lat,lang);
// create a new map by passing HTMLElement
let element: HTMLElement = document.getElementById('map');
let map: GoogleMap = this.googleMaps.create(element);
// create CameraPosition
let position: any = {
target: LatLng,
zoom: 18,
tilt: 30
};
map.one(GoogleMapsEvent.MAP_READY).then(() => {
console.log('Map is ready!');
// Now you can add elements to the map like the marker
map.moveCamera(position);
// create new marker
let markerOptions:any = {
position: LatLng,
title: 'Ionic'
};
const marker:any = map.addMarker(markerOptions)
.then((marker: Marker) => {
marker.showInfoWindow();
});
});
}
The above code works fine on android
when i try to get current location of user and and pass lat, lang to another
function then i will not work
below is my code which is not working
code not working on android: ask permission but doesn't work
import { Geolocation ,GeolocationOptions } from '@ionic-native/geolocation';
constructor(...,public googleMaps: GoogleMaps,private geolocation : Geolocation) {
}
ionViewDidLoad() {
this.loadMap();
}
loadMap(){
this.geolocation.getCurrentPosition().then((position) => {
this.loadMapHandler(position.coords.latitude,position.coords.longitude);
}, (err) => {
console.log(err);
});
}
loadMapHandler(lat,lang) {
console.log(lat,lang); // console.log('is giving map co-ordinates');
// create a new map by passing HTMLElement
let element: HTMLElement = document.getElementById('map');
let map: GoogleMap = this.googleMaps.create(element);
let ionic: LatLng = new LatLng(lat,lang);
// create CameraPosition
let position: any = {
target: LatLng,
zoom: 18,
tilt: 30
};
map.one(GoogleMapsEvent.MAP_READY).then(() => {
console.log('Map is ready!');
// Now you can add elements to the map like the marker
map.moveCamera(position);
// create new marker
let markerOptions:any = {
position: LatLng,
title: 'Ionic'
};
const marker:any = map.addMarker(markerOptions)
.then((marker: Marker) => {
marker.showInfoWindow();
});
});
}
Thanks in Advance!!!