Google Places API現在通常可用。我正嘗試在jQuery中使用.ajax()調用來調用Google Places。我一直收回的錯誤是未捕獲的SyntaxError:意外的令牌:使用jQuery查詢Google Places API
我正在使用jQuery 1.5.2。我也嘗試過1.5.1,但結果相同。如果我能幫上忙的話,我寧願不移動到1.6.1。
我剛剛對其他API做了這樣的ajax調用,但是在Google Places中遇到了問題。下面是你可以玩的一個非常基本的代碼示例。你需要去獲得在API控制檯谷歌報價(https://code.google.com/apis/console)
jQuery.noConflict();
jQuery(document).ready(function(){
var url = 'https://maps.googleapis.com/maps/api/place/search/json';
jQuery.ajax({
url: url,
dataType: 'jsonp',
type: 'GET',
data: {
location: '33.787794,-117.853111',
radius: 1000,
name: 'coffee',
key: 'your_key', // add your key here
sensor: 'false'
},
// on success
success: function(data, textStatus, jqXHR){
console.log(data);
},
// on failure
error: function (jqXHR, textStatus, errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
});
該服務的谷歌地圖API服務條款要求的API(包括各種網絡服務,如地理編碼和地點)可與「Google地圖」結合使用。這意味着,當在網頁中使用服務時(這是JSONP的用處),您將需要加載API來顯示地圖,所以沒有理由不使用相關的API類來訪問這些服務。在許多情況下,無論如何這都更容易,因爲您不必構造或URL編碼URL,並且結果會轉換爲相關的Maps API對象(例如,google.maps.LatLng)。 – 2011-05-24 01:07:56
@Thor很高興知道,謝謝! – 2011-05-24 01:29:12
@Thor,我不認爲這是真的,因爲他們發佈是公開的。該文檔現在狀態...「如果您的應用程序在頁面上顯示Places API數據或視圖不顯示Google Map,則必須顯示帶有該數據的」由Google支持「徽標。」 – hemmeter 2011-05-25 17:49:02