AxeOwl
October 8, 2018, 10:46am
1
Hi to all, I’m trying to geolocate user in yours current position with ionic-native/geolocation plugin.
My snippet of code is:
this.geolocation.getCurrentPosition().then(res => {
this.myLat = res.coords.latitude;
this.myLon= res.coords.longitude;
this.reverseGeocoding(this.myLat,this.myLon);
console.log(this.start);
this.map = new google.maps.Map(this.mapElement.nativeElement, {
zoom: 7,
center: {lat: this.myLat, lng: this.myLon}
});
this.directionsDisplay.setMap(this.map);
this.addMarker(this.map);
}).catch((error) => {
console.log('Error getting location', error);
});
On browser it works but on android devices not. What is the trouble? Thanks in advance
what error does it output??
AxeOwl
October 8, 2018, 2:14pm
3
On browser it works fine, on mobile device there is no error but map doesn’t load. this.geolocation.getCurrentPosition().then( res => {}) isn’t carry out
Using android device or ios??
AxeOwl
October 9, 2018, 9:15pm
5
Android device, I said that in first answer
If you want to create Google map app, I recommend you use @ionic-native/google-maps
.
The plugin provides the same API for native Google Maps SDK for Android/iOS and Google Maps JavaScript API v3.
https://docs.google.com/presentation/d/e/2PACX-1vScoho1ensbR4qCI9AIuQN55BZVvK73pAjI7sumDvW3CrxxHnrmpXWUjx2-8CpFibqU1EjLKCRhuthJ/pub?start=false&loop=false&delayms=3000&slide=id.p
And it also provide original Geolocation API.
# LocationService class
```typescript
import { Platform } from 'ionic-angular';
import {
LocationService,
GoogleMap,
GoogleMapOptions,
MyLocation
} from '@ionic-native/google-maps';
export class MapPage {
map: GoogleMap;
constructor(private platform: Platform) {
this.platforms.ready(()=> {
this.loadMap();
});
}
This file has been truncated. show original
I had a similar issue recently - geolocation.getCurrentPosition() wasn’t returning anything.
A device restart got this working for me.
AxeOwl
October 10, 2018, 6:42pm
8
When I use ionic-native/google-maps plugin there is an error on my app:
Error: "Uncaught (in promise): TypeError: plugin is undefined
checkAvailability@http://localhost:8100/build/vendor.js:78342:9
LocationService.getMyLocation
but I’ve installed plugin with these two commands:
npm install @ionic-native/core @ionic-native/google-maps
ionic cordova plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="..." --variable API_KEY_FOR_IOS="..."
I guess you forget to wait platform.ready()
.
And also ionic serve
does not work, because it does not load cordova
.
Use ionic cordova run (browser/ios/android)
instead.
Adding -l
gives the live reload ability.
AxeOwl
October 10, 2018, 8:03pm
11
Now the error is: Error: "Uncaught (in promise): TypeError: google.maps.LocationService is undefined