-->

在Web浏览器中的位置检测[关闭](location detection in web browse

2019-08-02 05:23发布

我正在寻找定位用户位置的方法在访问我的网站,我已经试过的MaxMind,但他们似乎是在城市水平不准确的。 我想要的信息是(国家,城市,经度,纬度)我希望国家和城市是如果可能的话非常准确。

我还使用了HTML5,但它要求我的用户问题,分享这似乎是我不好解决的位置信息。 (althougth我得到了非常准确的结果)

任何解决方案?

注意:我发现谷歌搜索得到一个准确的检测,没有“要求分享我的位置”,但我没有发现任何API来使用谷歌服务

Answer 1:

这是一个代码,我发现使用谷歌地图..希望这是有用的地理定位的教程。

这适用于您连接到网络的方式。

  • 如果您使用的是Boradband ISP什么给你一个固定的IP您的位置将更加准确。
  • 如果你使用的移动设备连接到互联网,最近的手机塔从网络获取信号的位置将显示

例如用于HTML5地理位置

<!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>


Answer 2:

  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

我希望这些链接可以帮助你。 前两个环节有地理位置信息的数据库相对于IP地址。 而链接3,4,及对traceroute命令5的工作。 让我知道如果这些为你工作。



Answer 3:

IP地址可以改变依赖于ISP,我想这就是为什么地理位置数据库并不总是准确的原因。 您可以比较比其他的MaxMind这些地理位置站点之间的准确度。 www.geobytes.com , www.hostip.info , www.ip2location.com



文章来源: location detection in web browser [closed]