2012-03-20 11 views

答えて

5

あなたはこれらのように、場所のAPIにIPを使用する必要があります。

http://ipinfodb.com/ip_location_api_json.php

http://www.ipaddressapi.com/($)

など他のソースからのデータを取得するために管理します。

http://www.iplocation.net/

http://ip2loc.jerodsanto.net/

+0

言及する価値もう一つ:http://www.maxmind.com/app/ip-location(無料版は存在しますが、有料版のみが市を持っています正確に覚えていれば精度) – Corbin

+0

この方法はひどく不正確かもしれないと言っておく価値があります。私にとって最も近いと言えるのは、「英国」です。確かに、まるで地方レベルにはなりません。 –

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> 

関連する問題