Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why HTML5 Geolocation?

Why does HTML5 geolocation let you share your location? What is main purpose of using geolocation, as you can get the location with IP address as well. Is there any difference between these two methods?

I'm asking because geolocation requires the user's permission and also doesn't work on all browsers.

like image 615
mari Avatar asked Sep 24 '11 20:09

mari


2 Answers

HTML5 GeoLocation tends to be much more accurate than IP-based GeoLocation.

IP-based GeoLocation depends on databases associated with ISPs to figure out where you are. This doesn't work well when your ISP services a very large area and gives out dynamic IP addresses. The address in one town today might be 100 miles away tomorrow. Furthermore, those databases are usually not updated frequently. If your ISP sells off blocks of IPs or moves them to a new town, the database may still incorrectly think you're somewhere else.

HTML5 location uses services provided by your browser to figure out where you are. If your computer has GPS built-in (such as on many mobile devices and some laptops), it will know exactly where you are. This makes it much more useful for webapps that have a navigation or location component. For devices without GPS, it can often provide a very good approximation based on nearby known wireless signals and other factors, such as tracing what routers your computer goes through when connecting to the internet. The exact implementation depends on the computer, what hardware it has available, and how the browser chooses to do things.

For example, when I check an IP-based location service, it says that I'm in a particular large city in the same general area that I live in, but it's actually about 50 miles away. When I use an HTML5 location based service to figure out where I am, it's only off by about 20 blocks.

If you're developing a webapp which needs location data, try using HTML5 GeoLocation if at all possible. Set up a fallback, so that if HTML5 location fails, you can use an GeoIP solution instead. This way, you will get optimal accuracy on supported browsers and devices, but will still have a solution in place when the HTML5 data are not available.

If you used the geolocation-javascript project from Google Code, you could use the following code:

//determine if device has geo location capabilities
if(geo_position_js.init()){
   geo_position_js.getCurrentPosition(success_callback,error_callback);
}
else{
   // use an AJAX request to look up the location based on IP address
}
like image 186
nhinkle Avatar answered Sep 23 '22 16:09

nhinkle


Geolocation is a lot more precise than IP address, though both can be faked.

IP address just gives you country and general region.

Geolocation gives you:

  • Geographic coordinates (latitude and longitude)
  • Speed (assuming you're on a device that can measure this; most tablets and smartphones can)
  • Altitude (this is also dependent on the device)
  • Degrees clockwise from north (again, assuming the device supports this)

http://diveintohtml5.ep.io/geolocation.html has some good info on geolocation and the HTML5 geolocation API. Here's the W3C Candidate Recommendation.

like image 35
Peter C Avatar answered Sep 26 '22 16:09

Peter C