Google Places API
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
精彩评论