ユーザーの IP を緯度と経度にジオコーディングするために呼び出すことができるオープンな RESTful API を知っている人はいますか?
理想的には、http: //google.com/geocode_api/ ?IP=1.2.3.4 のようなもので、緯度と経度を返します。
ユーザーの IP を緯度と経度にジオコーディングするために呼び出すことができるオープンな RESTful API を知っている人はいますか?
理想的には、http: //google.com/geocode_api/ ?IP=1.2.3.4 のようなもので、緯度と経度を返します。
これは簡単な呼び出しのカップルです...
呼び出しの例:-
返される XML (ipinfodb) の例:-
<Response>
<Ip>122.169.8.137</Ip>
<Status>OK</Status>
<CountryCode>IN</CountryCode>
<CountryName>India</CountryName>
<RegionCode>10</RegionCode>
<RegionName>Haryana</RegionName>
<City>Kaul</City>
<ZipPostalCode></ZipPostalCode>
<Latitude>29.85</Latitude>
<Longitude>76.6667</Longitude>
<Timezone>0</Timezone>
<Gmtoffset>0</Gmtoffset>
<Dstoffset>0</Dstoffset>
</Response>
私のサイトでは、IP アドレスから場所を取得するためにhttp://ip-api.com/を使用しています。適切な制限があります(1 分あたり最大 150 リクエスト)。Ipinfo.io は、 1 日あたり1000 リクエスト未満の場合のみ無料です。
これはサンプル出力です:
(
[as] => AS8075 Microsoft Corporation
[city] => Redmond
[country] => United States
[countryCode] => US
[isp] => Microsoft bingbot
[lat] => 47.674
[lon] => -122.1215
[org] => Microsoft bingbot
[query] => 157.55.39.67
[region] => WA
[regionName] => Washington
[status] => success
[timezone] => America/Los_Angeles
[zip] => 98052
)
これは、使用できる PHP コードです。
$ip = $_SERVER['REMOTE_ADDR'];
$result = json_decode(file_get_contents("http://ip-api.com/json/{$ip}"));
//print_r ($result);
echo "{$result->lat},{$result->lon}";//48.156,17.142
Google API を使用できます: http://code.google.com/apis/ajax/documentation/#ClientLocation
編集
例:
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABCDEFG"></script>
<script type="text/javascript">
google.load("maps", "2.x", {callback: initialize});
function initialize() {
if (google.loader.ClientLocation) {
var lat = google.loader.ClientLocation.latitude;
var long = google.loader.ClientLocation.longitude;
alert ("lat: " + lat + "\nlong: " + long);
}
else { alert ("not available"); }
}
</p>
あなたは常にここで更新される無料のGeoデータベースを見つけることができます http://www.maxmind.com/app/geolitecity
また、 http://www.maxmind.com/app/csharpのようにこのGeo DBを使用するための新しいC#サービスを作成できます 。
以下のリンクhttp://www.maxmind.com/app/lookup_cityでオンラインで試すことができ ます