Created
July 3, 2021 15:47
-
-
Save muhammadawaisshaikh/7c94776a82f1969414917b7394753bef to your computer and use it in GitHub Desktop.
getting location (lat, lng) using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class LocationService { | |
constructor() { } | |
// getting lat,lng - once | |
getPosition(): Promise<any> { | |
return new Promise((resolve, reject) => { | |
navigator.geolocation.getCurrentPosition(resp => { | |
resolve({ lng: resp.coords.longitude, lat: resp.coords.latitude }); | |
}, | |
err => { | |
reject(err); | |
}); | |
}); | |
} | |
// getting lat,lng - Continously | |
getPositionContinously(): Promise<any> { | |
return new Promise((resolve, reject) => { | |
navigator.geolocation.watchPosition(resp => { | |
resolve({ lng: resp.coords.longitude, lat: resp.coords.latitude }); | |
}, | |
err => { | |
reject(err); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getting Place Name using lat, lng from google maps api:
https://developers.google.com/maps/documentation/geocoding/overview?csw=1#ReverseGeocoding