2015-12-19 28 views
-1

我正在創建一個web應用程序,我需要在地圖上顯示信息。但我需要將EPSG:3301的座標轉換爲EPSG:4326。有網站你可以做到http://spatialreference.org/projection/?json= {「geometry」:{「type」:「Point」,「coordinates」:[527742.81,6561591.74]}} & inref = EPSG:3301 & outref = EPSG:4326。 所以,我有我的代碼:ajax跨域請求返回的數據錯誤

$("#btn1").click(function(event){ 
var searchString = $('input[name=check_list1]:checked', '#myForm').val(); 
var data1   = 'search='+ searchString; 
if(searchString) { 
    $.ajax({ 
     type: "POST", 
     url: "do_search.php", 
     data: data1, 
     dataType: 'json', 
     success: function(data){ 
      var otsing_data = (data);    
      var json_url = "http://spatialreference.org/projection/?json={'geometry':{'type':'Point', 'coordinates':["+otsing_data['x']+", "+otsing_data['x']+"]}}&inref=EPSG:3301&outref=EPSG:4326"; 
      $.ajax({ 
       type: 'GET', 
       url: json_url, 
       async: false, 
       contentType: "application/json", 
       dataType: 'jsonp', 
       }).done(function (data) { 
       var test = data; 
       console.log(test); 
      }); 
     } 
    });  
} 
// return false; 
}) 

但執行console.log(測試)返回我

Object {error: "Expecting property name: line 1 column 1 (char 1)"} 
+0

此錯誤從您通過ajax get方法調用的API返回。控制該URL並直接通過瀏覽器調用。你會得到相同的輸出。 –

+0

你是什麼意思?你能解釋一下嗎?我需要處理我應該回來的數據。 – WKoppel

+0

console.log(json_url);並在瀏覽器中找到該URL並查看結果。例如,我認爲這是與api調用不與jquery ajax跨域 –

回答

0

我需要改變

var json_url = "http://spatialreference.org/projection/?json={'geometry': {'type':'Point', 'coordinates':["+otsing_data['x']+", "+otsing_data['x']+"]}}&inref=EPSG:3301&outref=EPSG:4326"; 

var json_url = 'http://spatialreference.org/projection/?json={"geometry":{"type":"Point", "coordinates":['+point_x+', '+point_y+']}}&inref=EPSG:3301&outref=EPSG:4326';