Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About Geolocation in HTML 5

Google Maps can now pinpoint my location with street precision with the help of Firefox.

I understand this is a new feature of HTML 5 compatible browsers and that the location is fetched by using some sort of feature of the connected WiFi network (I hope I'm not making any silly assumptions).

What I intend to know is how this whole process exactly works:

  • Why only in HTML 5?
  • Why / how does Firefox ask me to share my location with Google Maps?
  • What is the normal precision one can count on?
  • How can I implement this feature in my websites?

Thanks in advance!

like image 298
Alix Axel Avatar asked Feb 11 '10 22:02

Alix Axel


People also ask

What is geolocation in HTML5?

Geo-location in HTML5 is used to share the location with some websites and be aware of the exact location. It is mainly used for local businesses, restaurants, or showing locations on the map. It uses JavaScript to give latitude and longitude to the backend server. Most of the browsers support Geolocation API.

What is the use of geolocation?

Geolocation refers to the use of location technologies such as GPS or IP addresses to identify and track the whereabouts of connected electronic devices. Because these devices are often carried on an individual's person, geolocation is often used to track the movements and location of people and surveillance.

What is geolocation example?

Geolocation data generally fulfills one or more of three functions. The most common example is providing the location of an object on Earth through longitude and latitude coordinates. It can also add location information to a digital artifact such as a photo or social media post.

Which is correct about Geolocation API in HTML5?

Q 6 - Which of the following is correct about geolocation api in HTML5? A - HTML5 Geolocation API lets you share your location with your favorite web sites.


2 Answers

How does it work?

When you visit a location-aware website in Firefox, the browser will ask you if you want to share your location.

If you consent, Firefox gathers information about nearby wireless access points and your computer’s IP address, and will get an estimate of your location by sending this information to Google Location Services (the default geolocation service in Firefox). That location estimate is then shared with the requesting website. (Source)

How accurate are the locations?

Accuracy varies greatly from location to location. In some places, the geolocation service providers may be able to provide a location to within a few meters. However, in other areas it might be much more than that. All locations are to be considered estimates as there is no guarantee on the accuracy of the locations provided. (Source)

In my case, Firefox reports that I am about 10km away from my real location.

How do I use this feature in my website?

You would do something like this:

if (navigator.geolocation) {      navigator.geolocation.getCurrentPosition(function(position) {            alert(position.coords.latitude + ", " + position.coords.longitude);          // Use the latitude and location as you wish. You may set a marker         // on Google Maps, for example.     });  }  else {     alert("Geolocation services are not supported by your browser."); }   

You can see an online demo here: Firefox HTML 5 Geolocation Demo (Requires a geolocation-aware browser such as Firefox 3.1b3.)

like image 128
Daniel Vassallo Avatar answered Oct 15 '22 05:10

Daniel Vassallo


HTML5 supplies an API

which allows the web browser (and then hence the server-side of an web application) to query the location and related information such as speed (if relevant), in a standard, uniform, fashion.

The host and its web browser supply the "devices" which compute/estimate the geolocation per-se

For this API to be useful, requires that the underlying host and web browser
  a) allow the sharing of such info (note the privacy issue) and
  b) be somewhat equipped (either locally or by way of the network they are hooked-up to) to read or estimate the geolocation.

The techniques and devices involved in computing the actual location involves a combination of the following (not all apply of course), and is independent from the HTML 5 standard:

  • GPS device (lots of phones now have them)
  • Routing info at the level of the Cell phone network
  • IP address / ISP routing information
  • Wifi router info
  • Fixed data, manually input (for pcs which are at a fixed location)
  • ...

Therefore...
- HTML5 alone cannot figure out geolocation: upgrading to newer web browser, in of itself, won't be sufficient to get geolocation features in your applications etc.
- Geolocation data can be shared outside of the HTML5 API, allowing GPS-ready or GeoLocation-ready phones expose the geolocation data within other APIs.

like image 38
mjv Avatar answered Oct 15 '22 05:10

mjv