Skip to main content
 首页 » 编程设计

jquery之Ajax 和 Places API 获取请求

2026年10月07日4mfrbuaa

我无法向 Google Places API 发送 AJAX 请求。代码:

$.ajax({ 
    type: 'GET', 
    url:'http://maps.googleapis.com/maps/api/place/textsearch/json?', 
    dataType: 'json', 
    data: { 
        'query' : "restaurants+in+" + cityname, 
        'key' : MyPublicKey, 
        'sensor' : "false" 
    }, 
    success: function(restaurans) { 
        console.log(restaurants); 
    } 
}); 

我做错了什么?

请您参考如下方法:

我猜REST API不能这样使用(我猜原因之一应该是CORS)

参见Google Places API

Looking to use this service in a JavaScript application? Check out the Places Library of the Google Maps API v3.

这应该会引导你

https://developers.google.com/maps/documentation/javascript/places

及其“文本搜索请求”部分提供了 Google 文本搜索服务对象的示例