问题
today i realize that some pages can locate me (im using a laptop with no gps built-in) using google chrome with a an very impresive exactitude, i know that using my IP you can locate me, but not with such presision. Now in google maps you will see a button on top of the yellow men (street view) who locates you using google chrome.
How does this work? There is an API to use that?
回答1:
It's also possible with the actual HTML 5 Geolocation functions (only if your browser supports):
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
alert("Not Supported!");
}
function success(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
}
function error(msg) {
console.log(typeof msg == 'string' ? msg : "error");
}
var watchId = navigator.geolocation.watchPosition(function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});
navigator.geolocation.clearWatch(watchId);
Greetings, Sascha
回答2:
Check out the help page
The local network information used by Google Location Services to estimate your location includes information about visible WiFi access points, including their signal strength; information about your local router; your computer's IP address. The accuracy and coverage of Google Location Services will vary by location.
回答3:
Here is a link to the Firefox code that allows you to access the Google Location Service: http://mxr.mozilla.org/mozilla1.9.1/source/dom/src/geolocation/NetworkGeolocationProvider.js
Enjoy!
来源:https://stackoverflow.com/questions/3343562/how-google-chrome-knows-my-current-gps-location-and-how-to-use-it-in-my-code