1
votes

I'm trying to write a simple JS function that gets some info from the Google Maps places API. I wrote this function:

function makeCall(url) {
    var data = $.ajax({
         type: "GET",
         url: url,
         async: false
    });
    return data
}

An example URL that I am passing is this (with the key removed) https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7746031,-122.654422&rankby=distance&opennow=true&name=REI&key=API_KEY

This works fine locally, but I keep getting the cross domain request error when I try it on my server. I've tried just about everything, jsonp, requestJSON, a proxy, and I can't seem to get it to work. Is there a better way to do this?

Thanks.

1
Is there a reason you can't use the Places Library in the Google Maps Javascript API v3? - geocodezip

1 Answers

0
votes

Fixed this by writing a simple php file to take care of the GET request. The javascript POSTs to the php script, which then makes the call to Google's API.