2014-03-12 61 views
2

我是jQuery的新手,基於JSFiddle,我寫了一個腳本來定位自己。這裏是我的腳本:爲什麼我無法從此jsonp響應中獲取位置?

 $(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,但是,該位置可以恢復。

如何檢索位置座標? :)

+4

更新你錯過了在'$( 「位置」)一個''##。HTML()' – fiction

+0

@fiction現在,我想拍我自己x( –

+1

它發生在我身上,不要擔心:) – fiction

回答

3

嗨,你錯過了$( 「#位置」),它是在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"); 
相關問題