How does HTML 5 Geolocation works?
Asked Answered
M

3

7

I know many people have asked this question but i don't think i found a proper answer. My question is when you run the HTML 5 Geolocation API on desktop in firefox and you click on share location it takes your IP Address but how does it know which wireless points it has to use so it find your distance? i run the app at home and i get accuracy 50 m but i go next door to my neighbour who has same internet provider and on his desktop i receive back accuracy 18 km out? So if someone can explain this to me or point me where to read this information would be very helpful?

Thank you

Merkle answered 18/5, 2011 at 14:21 Comment(2)
possible duplicate of How HTML5 Geolocation Feature Works?Southing
Possible duplicate of How does HTML5 Geolocation Work?Exorcism
E
0

The geolocation API lets you share your location with trusted web sites. The latitude and longitude are available to JavaScript on the page, which in turn can send it back to the remote web server and do fancy location-aware things like finding local businesses or showing your location on a map.

What happens during that call to getCurrentPosition()? As I mentioned at the beginning of this chapter, geolocation support is opt-in. That means your browser will never force you to reveal your current physical location to a remote server. The user experience differs from browser to browser. In Mozilla Firefox, calling the getCurrentPosition() function of the geolocation API will cause the browser to pop up an “infobar” at the top of the browser window.

The call to getCurrentPosition() will return immediately, but that doesn’t mean that you have access to the user’s location. The callback function will be called with a single parameter, an object with two properties: coords and timestamp. The timestamp is just that, the date and time when the location was calculated. (Since this is all happening asynchronously, you can’t really know when that will happen in advance. It might take some time for the user to read the infobar and agree to share their location. Devices with dedicated GPS hardware may take some more time to connect to a GPS satellite. And so on.) The coords object has properties like latitude and longitude which are exactly what they sound like: the user’s physical location in the world.

You can refer this link from where i have taken the above information: http://diveintohtml5.ep.io/geolocation.html

Ellita answered 2/6, 2011 at 9:15 Comment(0)
A
0

W3C Geolocation API is built on existing technologies, and is heavily influenced by Google Gears Geolocation API. In fact, Firefox's Geolocation implementation uses Google's network location provider.

Google Gears Geolocation works by sending a set of parameters that could give a hint as to where the user's physical location is, to a network location provider server, which is by default, the one provided by Google (code.l.google.com). Some of the parameters are a list of mobile cell towers and their signal strengths, as well as a list of detected Wi-Fi networks and their signal strengths. These parameters are encapsulated into a JSON message and sent to the network location provider via HTTP POST. Based on these parameters, the network location provider can deduce the location.

"If you allow a website to get your location via this service, we (google) will collect, depending on the capabilities of your device, information about the wifi routers closest to you, cell ids of the cell towers closest to you, and the strength of your wifi or cell signal. We use this information to return an estimated location to the Firefox browser and the Firefox browser sends the estimated location to the requesting website. For each request sent to our (google) service, we (google) also collect IP address, user agent information, and unique identifier of your client. We use this information to distinguish requests, not to identify you."

Sources : http://www.google.com/intl/en/privacy/lsf.html and http://en.wikipedia.org/wiki/W3C_Geolocation_API

Asphyxiant answered 27/6, 2011 at 22:36 Comment(0)
F
0

HTML5 Geolocation API uses certain features, such as Global Positioning System (GPS), Internet Protocol (IP) address of a device, nearest mobile phone towers, and input from a user, in the users’ device to retrieve the users’ location. The users’ location retrieved by using the Geolocation API is almost accurate depending upon the type of source used to retrieve the location.

There is a really good demo of HTML5 Geolocation here (http://html5demos.com/geo). Whenever a website tries to fetch your location by using one of the following mentioned APIs, the browser will ask me your permission before invoking the API to share your location.

The Geolocation API provides the following methods:

  • getCurrentPosition(successCallback, errorCallback, options)

    Used to retrieve the current geographical location of a user.

  • watchPosition(successCallback, errorCallback, options)

    The function returns a watchId and calls successCallback with the updated coordinates. It continues to return updated position as the user moves (like the GPS in a car).

  • clearWatch(watchId)

    Stops the watchPosition() method based on the watchId provided.

Sample Code:

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(userPositionSuccess, userPositionError);
} else {
  alert("Your browser does not support geolocation.");
}

function userPositionSuccess(position) {
  alert("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude);
}

function userPositionError() {
  alert("There was an error retrieving your location!");
}
Furnary answered 22/12, 2013 at 23:59 Comment(1)
your demo page fails on desktop browsers, I suspect it's out of date if you have an update for itMailbox

© 2022 - 2024 — McMap. All rights reserved.