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