3

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 (Country, City, longitude, latitude) i want the country and the city to be very accurate if possible.

I have also used HTML5 but the problem that it asks my user to share location information which seems to me bad solution. (althougth i got very accurate results)

Any solutions?

Notice: i found google search got an accurate detection and without "ask for sharing my location", but i didn't find any api to use google service

4

3 に答える 3

3

これは、Google マップを使用した Geo Location のチュートリアルで見つけたコードです。お役に立てば幸いです。

これは、ネットワークに接続する方法で機能します。

  • 固定 IP を提供する Boradband ISP を使用すると、位置情報がより正確になります。
  • モバイル デバイスを使用してインターネットに接続している場合、ネットワークが信号を取得している最寄りのモバイル タワーの場所が表示されます。

HTML5 Geolocation の例

<!DOCTYPE html>
<html>
<head>
<title>GeoLocation Demo</title>
<meta charset="utf-8"/>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script>
  var startPos;
  var map;

  function init() {
      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>";
      }
  }

  function updateLocation(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!"
      });

  }

  function handleLocationError(error) {
      switch (error.code) {
          case 0:
              updateStatus("There was an error while retrieving your location: " + error.message);
              break;

          case 1:
              updateStatus("The user prevented this page from retrieving the location.");
              break;

          case 2:
              updateStatus("The browser was unable to determine your location: " + error.message);

              break;

          case 3:

              updateStatus("The browser timed out before retrieving the location.");

              break;
      }
  }

  function updateStatus(msg) {
      document.getElementById("divStatus").innerHTML = msg;
  }
</script>
</head>

<body onload="init()">  
<div id="support"></div>
<div id="divStatus"></div>
<div id="map_canvas" style="width:600px;height:400px;"></div>
</body>
</html>
于 2012-11-02T06:23:20.410 に答える
1
  1. www.ipfingerprints.com
  2. www.geoiptool.com/
  3. http://www.geobytes.com/TraceRouteLocator.htm
  4. http://whatismyipaddress.com/traceroute-tool
  5. http://www.dnsqueries.com/en/ip_geographical_informations.php

これらのリンクがお役に立てば幸いです。最初の 2 つのリンクには、IP アドレスに関する位置情報のデータベースがあります。一方、リンク 3、4、および 5 は traceroute コマンドで機能します。これらがうまくいくかどうか教えてください。

于 2013-01-22T15:43:05.503 に答える
0

IP アドレスは ISP によって変更される場合があり、それが位置情報データベースが常に正確であるとは限らない理由だと思います。maxmind 以外のこれらのジオロケーション サイト間で精度を比較できます。 www.geobytes.comwww.hostip.infowww.ip2location.com

于 2012-11-02T10:03:31.347 に答える