4

for any reason this code doesn't seem to work

var request = "https://maps.googleapis.com/maps/api/place/search/json?";
request = request + "location="+lat+","+lng+"&";
request = request + "radius=500&";
request = request + "types=&";
request = request + "name=&";
request = request + "sensor=false&";
request = request + "key="+key;

$.getJSON(request, function(data){ alert(data); });

The string is valid and i get the result if i just load it in my browser. Do you see anything wrong here?

EDIT: alright, problem solved. The Google Places API actually does not accept ajax jsonp calls. I'll have to use their javascript API instead. See this thread for more details:

How do I use Google Places to get an array of Place names?


Thanks for your replies. So I now make the API call with the following code:

    $.ajax({
    url: "https://maps.googleapis.com/maps/api/place/search/json",
    dataType: 'jsonp',
    data: {
        location:lat+","+lng,
        radius:500,
        types:"",
        name:"",
        sensor:"false",
        key:key
    },
    success: function(data) {
        alert(data);
    }
});

Whiich doesn't show any alert box. By inspecting the code, I catch an error message:

   "html_attributions" : [],
  json:2Uncaught SyntaxError: Unexpected Token :

"results" : [ {

However, following this error message, in the console, the requested data actually shows in the "results" field... Any idea?

3
  • 1
    This needs some more context; where is this code being executed, and where are lat, lng, and key defined? Commented May 27, 2011 at 17:16
  • Are you getting a specific error message in the console? Commented May 27, 2011 at 17:28
  • en.wikipedia.org/wiki/Same_origin_policy Commented May 27, 2011 at 17:28

1 Answer 1

1

The Google Places API doesn't support JSONP requests.

Sign up to request clarification or add additional context in comments.

2 Comments

Great to know but a reference would be wonderful for more information.
@agrothe You can't proof that something is absent with reference, like the god for example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.