Location Detection In Web Browser
I am searching for a method to locate the user location while visiting my website, i have tried Maxmind but they seems to be inaccurate in the city level. the information i want is
Solution 1:
This is a code i found for a tutorial for Geo Location using Google maps.. Hope this is useful.
This works on the way you connect to the network.
- if you use a Boradband ISP what gives you an fixed ip your location will be more accurate.
- if you use mobile device to connect to internet, the Location of the nearest Mobile tower from which your network gets the signal will be shown
Example for HTML5 Geolocation
<!DOCTYPE html><html><head><title>GeoLocation Demo</title><metacharset="utf-8"/><scriptsrc="http://maps.google.com/maps/api/js?sensor=false"type="text/javascript"></script><script>var startPos;
  var map;
  functioninit() {
      if (navigator.geolocation) {
          document.getElementById("support").innerHTML = "<p style='color:green'>Great! This browser supports HTML5 Geolocation</p>";
          navigator.geolocation.getCurrentPosition(updateLocation, handleLocationError, {
              timeout: 50000
          });
          //navigator.geolocation.watchPosition(updateCurrPosition,handleLocationError);
      } else {
          document.getElementById("support").innerHTML = "<p style='color:red'>Oops! This browser does not support HTML5 Geolocation</p>";
      }
  }
  functionupdateLocation(position) {
      startPos = position;
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
      //document.getElementById("startLat").innerHTML = latitude;//document.getElementById("startLon").innerHTML = longitude;var coords = new google.maps.LatLng(latitude, longitude);
      var mapOptions = {
          zoom: 10,
          center: coords,
          mapTypeControl: false,
          navigationControlOptions: {
              style: google.maps.NavigationControlStyle.SMALL
          },
          mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
      var marker = new google.maps.Marker({
          position: coords,
          map: map,
          title: "Your current location!"
      });
  }
  functionhandleLocationError(error) {
      switch (error.code) {
          case0:
              updateStatus("There was an error while retrieving your location: " + error.message);
              break;
          case1:
              updateStatus("The user prevented this page from retrieving the location.");
              break;
          case2:
              updateStatus("The browser was unable to determine your location: " + error.message);
              break;
          case3:
              updateStatus("The browser timed out before retrieving the location.");
              break;
      }
  }
  functionupdateStatus(msg) {
      document.getElementById("divStatus").innerHTML = msg;
  }
</script></head><bodyonload="init()"><divid="support"></div><divid="divStatus"></div><divid="map_canvas"style="width:600px;height:400px;"></div></body></html>Solution 2:
- www.ipfingerprints.com
- www.geoiptool.com/
- http://www.geobytes.com/TraceRouteLocator.htm
- http://whatismyipaddress.com/traceroute-tool
- http://www.dnsqueries.com/en/ip_geographical_informations.php
I hope these links might help you. First two links have a database of geolocation information with respect to IP addresses. Whereas the links 3,4, & 5 work on traceroute command. Let me know if these work for you .
Solution 3:
The IP addresses may be changed depends on ISP and I think that is the reason why the geolocation database is not always accurate. You can compare the accuracy among these geolocation sites other than maxmind. www.geobytes.com, www.hostip.info, www.ip2location.com
Post a Comment for "Location Detection In Web Browser"