2

I'm trying to figure out how to use Google Places API. I have read all their documentation. I'm just trying to figure out how to get the data in the JSON response. I'm not trying to output the response to a map. I want to access things like place names, etc.

I was trying to use the $.getJSON jquery function in a previous post I made (http://stackoverflow.com/questions/11642418/trying-to-use-google-places-api-with-jquerys-getjson-function), however I couldn't get the browser to parse the JSON response accordingly, I'm thinking because the JSON response is in a remote server. I'm now trying to use JSONP but I have the same error.

<script type="text/javascript">

    function jasonPCall() {
        var url = 'https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=****my key****&callback=?';

        $.ajax({
            type: 'GET',
            url: url,
            async: false,
            jsonpCallback: 'jsonCallback',
            contentType: "application/json",
            dataType: 'jsonp',
            success: function (json) {

                console.log("We got a response.");
                console.dir(json.results[0].name);

            },
            error: function (e) {
                console.log("We didn't get a response.");
                console.log(e.message);
            }
        });
    }
</script>

Is what I'm trying to do possible? If so, how then are you supposed to access the JSON reply data provided by Google Places? Can someone post a simple example of the proper way to do it?

rocklandcitizen
  • 979
  • 4
  • 17
  • 27
  • PS. I realize this person has the same problem here (http://stackoverflow.com/questions/10023153/getting-json-file-from-google-places-api). I tried to follow the suggestions but there is no JSON object to parse because I get no JSON object back. – rocklandcitizen Aug 08 '12 at 18:48

1 Answers1

1

From what I recall, access to places api via javascript is not supported. You have to use the Places Library of the Google Maps javascript sdk to get to it. The first line of the places documentation at https://developers.google.com/places/documentation/ says "Looking to use this service in a JavaScript application? Check out the Places Library of the Google Maps API v3."