javascript - How to get city name by ip in google map? - Stack Overflow

Please help me to find cityname according to ip. Let me explain.I am developing a webpage where I want

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

You 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

相关推荐

  • javascript - How to get city name by ip in google map? - Stack Overflow

    Please help me to find cityname according to ip. Let me explain.I am developing a webpage where I want

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信