【问题标题】:Why am I unable to get the location from this jsonp response?为什么我无法从此 jsonp 响应中获取位置?
【发布时间】:2014-04-16 06:05:40
【问题描述】:

我是jQuery 的新手,基于 JSFiddle,我编写了一个脚本来定位自己。这是我的脚本:

       $(document).ready(function(){
            $.get("http://ipinfo.io", function (response) {
                $("#ip").html("" + response.ip);
                $("#hostname").html("" + response.hostname);
                $("#city").html("" + response.city);
                $("#region").html("" + response.region);
                $("#country").html("" + response.country);
                $("location").html("" + response.loc);
                $("#organisation").html("" + response.org);
            },"jsonp");
        });  

一切顺利,只是我无法获得位置。 In the JSFiddle,不过可以找回位置。

如何检索位置坐标? :)

【问题讨论】:

  • 您在$("location").html() 上缺少#
  • @fiction 现在我要拍自己x(
  • 这种事经常发生在我身上,别担心 :)

标签: javascript jquery html geolocation jsonp


【解决方案1】:

您好,您错过了 $("#location") # 它已在 JSFiddle 中更新

$.get("http://ipinfo.io", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#address").html("Location: " + response.city + ", " + response.region);
    $("#location").html("Location Lat Long:"+response.loc);
    $("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2020-07-17
    相关资源
    最近更新 更多