2011-07-29 198 views
0

我正在嘗試使用jQuery調用Google Places API 1,但由於跨域安全問題,它似乎失敗。我試圖讓這個請求成爲一個JSONP請求,並且它運行,但服務器直接返回JSON,所以解析在jQuery中失敗。有沒有人找到這個解決方案?Google Places API

var requestUrl = "https://maps.googleapis.com/maps/api/place/search/json?location=" + 
        location.coords.latitude + "," + location.coords.longitude + "&radius=100&types=restaurant&sensor=false&key=<<api key here>>"; 

// Called with 
$.getJSON(requestUrl + "&callback=?", onLocateRestaurants); 
// or 
$.ajax({ 
    url: requestUrl, 
    type: 'GET', 
    dataType: 'jsonp', 
    crossDomain: true, 
    callback: 'test', 
    contentType: 'application/json', 
    success: onLocateRestaurants2, 
    error: defaultErrorHandler 
}); 
+0

可以複製? http://stackoverflow.com/questions/6104122/querying-google-places-api-using-jquery –

+0

Places API不支持JSON-P。有關更多詳細信息,請參閱以上Ken所鏈接的問題。 – monsur

+0

你可以把這些答案作爲答案,以便我可以解決這個問題嗎? –

回答

2

@Jeremy:我可以爲您發佈結束的答案。

Places API不支持JSON-P。有關詳細信息,請參閱以下問題(如由肯·布朗寧鏈接):

Querying Google Places API using jQuery