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 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式