Please help me to find cityname according to ip. Let me explain.
I am developing a webpage where I want it to automatically fetch the city name where it is opened and it should also display the location in the google map automatically.
Please help me to find cityname according to ip. Let me explain.
I am developing a webpage where I want it to automatically fetch the city name where it is opened and it should also display the location in the google map automatically.
Share Improve this question asked Mar 20, 2012 at 8:46 RashtraRashtra 753 silver badges12 bronze badges2 Answers
Reset to default 5You should use an IP to location API, like these:
http://ipinfodb./ip_location_api_json.php
http://www.ipaddressapi./ ($)
Or manage to get data from other sources like:
http://www.iplocation/
http://ip2loc.jerodsanto/
Another source is: https://www.geoip-db. They provide a JSON and JSONP-callback solution.
- JSON: https://geoip-db./json/
- JSONP: https://geoip-db./json/geoip.php?jsonp=callback
A jQuery example:
<!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./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./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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309764a4621934.html
评论列表(0条)