There is another way to do this, you can just use the google http service.
if you use angular then first you will need to import this
import { Http, Headers, RequestOptions, Response } from '@angular/http';
or you can use a different method according to your scripting language. then add this code to one of the methods where you write over the code
let body = { enableHighAccuracy: true, timeout: 2000, maximumAge: 100 }; let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); this.http.post("https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY", body, headers).map((data: any) => data.json());
when you sign the result of the above http request, you will get the necessary data in json format, for example,
{ "location": { "lat": 21.1247647, "lng": 79.04754489999999 }, "accuracy": 625 }
use it as per your requirement. happy coding
source share