2
A
回答
5
您应该使用IP来定位API,像这样的:
http://ipinfodb.com/ip_location_api_json.php
http://www.ipaddressapi.com/($)
或管理得到像其他来源的数据:
0
另一个来源是:https://www.geoip-db.com它们提供JSON和JSONP回调解决方案。
甲jQuery的例子:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Geo City Locator</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body >
<div>Country: <span id="country"></span></div>
<div>State: <span id="state"></spa></div>
<div>City: <span id="city"></span></div>
<div>Latitude: <span id="latitude"></span></div>
<div>Longitude: <span id="longitude"></span></div>
<div>IP: <span id="ip"></span></div>
<script>
$.getJSON('https://geoip-db.com/json/geoip.php?jsonp=?').done(function(location) {
$('#country').html(location.country_name);
$('#state').html(location.state);
$('#city').html(location.city);
$('#latitude').html(location.latitude);
$('#longitude').html(location.longitude);
$('#ip').html(location.IPv4);
});
</script>
另外一个值得一提:http://www.maxmind.com/app/ip-location(免费版存在,但只有付费版才有城市精度,如果我没有记错的话) – Corbin 2012-03-20 08:54:34
也值得说这种方法可能是非常不准确的。你可以对我说的最接近“英国”,当然不是地区级的,更不用说城镇了。 – 2012-03-20 12:23:49