Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to get location of the client from the browser?

Tags:

geolocation

What i need is the lat/long of the client(via browser)

Found some articles on the net,found some in stack overflow itself(an old article) Get GPS location from the web browser. it was answered almost 18months ago -- wondering if there's any other(more efficient) way of getting the information of the location of the user from the browser.

Soo far,found 2

using Maxmind

  • http://coding.smashingmagazine.com/2010/03/08/entering-the-wonderful-world-of-geo-location/

Other,using google's api

  • http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/

w3c's geo api will have downward compatibility issues: http://dev.w3.org/geo/api/spec-source.html ,so not choosing that.

Found a site, www.drumaroo.com -- requests for the location to be shared the 1st time when we drop into the site.Needed something similar

like image 566
Vivek Chandra Avatar asked Sep 24 '11 09:09

Vivek Chandra


People also ask

How to get the location of a user in a browser?

If your browser supports Geolocation then you have to access navigator. geolocation object which provides the method and determines the user location. It depends on the method that you call on the geolocation object whether you need to just fetch the location data or you want to keep it monitoring continuously.

How to get the location of a website visitor?

Another way to get visitor's location is by using paid services from the list of APIs listed at IP Geolocation APIs . I'm going to show you how to identify user's location for free! CloudFlare serves tracing pages on every site hosted on their domain at /cdn-cgi/trace endpoint.

How do I get a user’s location from their IP address?

One way in which you can do this is by determining the user’s location from their IP Address (also referred to as Geo IP). Even though this method is not as accurate as the HTML Geolocation API (the level of accuracy is typically limited to the city the user is in), there are many instances where this is acceptable, for example:

How is the location of the user’s device determined?

The location provided by the user can be determined using GPS, WIFI, IP Geolocation, etc., which depends on the device used by the user. To protect the user’s privacy, it will first ask for permission to locate the device, and if the user grants permission, we can locate the device.


2 Answers

The user can be located by using following ways:-

  1. Using the IP addr. easiest to achieve but most unreliable due to the uncertainty of network addresses / topologies.
  2. Using the latitude, longitude pair most accurate solution, but most of the end users don’t know about their latitude, longitude value.
  3. Using the zipcodes nice to think but quite difficult to achieve, although ZipCodes are being used for
    quite a long time but this is not a standard yet. (see link
    http://en.wikipedia.org/wiki/Postal_code ). ZipCode alone is not sufficient for calculation of distance we need to convert it to latitude, longitude pair which is an
    overhead.
  4. Using user’s address most compelling thought since each user will have at least one geographic address. Address alone is not sufficient for calculation of distance we need to convert it to latitude, longitude pair which is an overhead.

The Best option will be to use options 2,3.4 together, You can do that in two steps:-

  1. First determine the latitude, longitude from the address.
  2. Then use this lat, long value for further processing i.e. storing in database etc.

For various options available for this see the answer of this question

like image 95
Amit Avatar answered Sep 25 '22 17:09

Amit


Try HTML5 geolocation

 function init() {


 var mapOptions = {
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP
 };


 map = new google.maps.Map(document.getElementById('map-canvas'),
  mapOptions);



if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
  var pos = new google.maps.LatLng(position.coords.latitude,
                                   position.coords.longitude);

  var infowindow = new google.maps.InfoWindow({
    map: map,
    position: pos,
    content: 'Location found using HTML5.'
  });

  map.setCenter(pos);
}

 } else {
alert('Geolocation not detected');   
}
}
like image 42
Asif hhh Avatar answered Sep 26 '22 17:09

Asif hhh