我正在寻找定位用户位置的方法在访问我的网站,我已经试过的MaxMind,但他们似乎是在城市水平不准确的。 我想要的信息是(国家,城市,经度,纬度)我希望国家和城市是如果可能的话非常准确。
我还使用了HTML5,但它要求我的用户问题,分享这似乎是我不好解决的位置信息。 (althougth我得到了非常准确的结果)
任何解决方案?
注意:我发现谷歌搜索得到一个准确的检测,没有“要求分享我的位置”,但我没有发现任何API来使用谷歌服务
我正在寻找定位用户位置的方法在访问我的网站,我已经试过的MaxMind,但他们似乎是在城市水平不准确的。 我想要的信息是(国家,城市,经度,纬度)我希望国家和城市是如果可能的话非常准确。
我还使用了HTML5,但它要求我的用户问题,分享这似乎是我不好解决的位置信息。 (althougth我得到了非常准确的结果)
任何解决方案?
注意:我发现谷歌搜索得到一个准确的检测,没有“要求分享我的位置”,但我没有发现任何API来使用谷歌服务
这是一个代码,我发现使用谷歌地图..希望这是有用的地理定位的教程。
这适用于您连接到网络的方式。
<!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>
我希望这些链接可以帮助你。 前两个环节有地理位置信息的数据库相对于IP地址。 而链接3,4,及对traceroute命令5的工作。 让我知道如果这些为你工作。
IP地址可以改变依赖于ISP,我想这就是为什么地理位置数据库并不总是准确的原因。 您可以比较比其他的MaxMind这些地理位置站点之间的准确度。 www.geobytes.com , www.hostip.info , www.ip2location.com