Current Location in Google Maps

I am following this tutorial:

It’s a nice tutorial. But in src/providers/locations.ts:

    let usersLocation = {
        lat: 40.713744, 
        lng: -74.009056

This is hard-coded.

What would be the way to dynamically plugin the users current location?

Thank you!

1 Like

Use Ionic Native and the geolocation plugin:

1 Like

Thank you!

I get the console to output the current location. It’s working.

What is the best way to save to a variable?

Something that looks like this:

  Geolocation.getCurrentPosition().then((resp) => {

   this.myLat = resp.coords.latitude;
   this.myLong = resp.coords.longitude;

  }).catch((error) => {
    console.log('Error getting location', error);

Check out this Repo