简体   繁体   中英

How get latitude and longitude of laptop (wifi) in Google Maps Geolocation API?

To get latitude and longitude of a mobile phone we can use Google Maps Geolocation API ( https://developers.google.com/maps/documentation/geolocation/intro?hl=en ) by sending a package with the following format: enter image description here

The Google Maps Geolocation API returns a location and accuracy radius based on information about cell towers and WiFi nodes that the mobile client can detect. However, I wonder that for a laptop, how the format of a sent package will be. Is there anyone willing to send me a sample format used to get the location of a laptop? Thanks so much.

You can just use

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(callback);
}

and browser colls your callback function with one argument like this:

   function setLocation(position) {
        userPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
   };

I'm probably late to answer, but someone might find this useful.

So, you'll need to Post a request to https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_KEY

The response will be something like this:

{
  "location": {
    "lat": 51.0,
    "lng": -0.1
  },
  "accuracy": 1200.4
}

You can get a key from Google Cloud Platform

All the details of the API are here Geolocation API Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM