开发者

Google Places API

开发者 https://www.devze.com 2023-03-23 17:40 出处:网络
I\'m trying to call Google Places API1 using jQuery but it seems to be failing because of a cross-domain security issue. I\'ve tried to make this request a JSONP request and it runs but the server ret

I'm trying to call Google Places API1 using jQuery but it seems to be failing because of a cross-domain security issue. I've tried to make this request a JSONP request and it runs but the server returns straight up JSON so the parsing fails within jQuery. Has anyone found a so开发者_如何学Clution for this?

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
});


@Jeremy: I can post the closing answer for you.

The Places API does not support JSON-P. See the following question (as linked to by Ken Browning) for more details:

Querying Google Places API using jQuery

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号