dongshao8125 2013-02-12 07:53
浏览 47
已采纳

使用IP地址查找纬度和经度

In my page I used the bingmap API to find the latitude and longitude of given address. Here is the script for that.

But What I need to do here is, how to get the zipcode by giving the IP address as input. Anybody can help me to achieve this functionality.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnSearch").click(function () {
                //check user has entered something first
                if ($("#txtAddress").val().length > 0) {
                    //send location query to bing maps REST api
                    $.getJSON('http://dev.virtualearth.net/REST/v1/Locations?query=' + $("#txtAddress").val() + '&key=mykey&jsonp=?', function (result) {
                        if (result.resourceSets[0].estimatedTotal > 0) {
                            var loc = result.resourceSets[0].resources[0].point.coordinates;
                            $("#results").html('latitude:' + loc[0] + ', longitude:' + loc[1]);
                        }
                        else {
                            $("#results").html("sorry that address cannot be found");
                        }
                    });
                }
                else {
                    $("#results").html("please enter an address");
                }
            });
        });
    </script>
    <label for="myaddress">Type an address:</label>
    <input type="text" id="txtAddress" />
    <input type="button" id="btnSearch" value="Find Location" />
    <p id="results"></p>
  • 写回答

1条回答 默认 最新

  • duanqiao9541 2013-02-12 08:09
    关注

    Try

    $ip = "YOUR_IP_ADDRESS";
    
    $_API = "API_KEY";
    $_URL = "http://api.ipinfodb.com/v3/ip-city/?key=$_API&ip=$ip&format=json";

    OutPut

    { "statusCode" : "OK", "statusMessage" : "", "ipAddress" : "YOUR_IP_ADDRESS", "countryCode" : "IN", "countryName" : "INDIA", "regionName" : "GUJARAT", "cityName" : "AHMEDABAD", "zipCode" : "ZIPCODE", "latitude" : "23.0333", "longitude" : "72.6167", "timeZone" : "+05:30" }

    API_KEY will be available at Ipinfodb.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题