0
$(document).ready(function () {
    $.getJSON('https://maps.googleapis.com/maps/api/place/textsearch/json?query=Kfc+sydney&sensor=true&key=AIzaSyD-jxenRCJipqw5Kg-HXQbRXUK8dHNFz3A',
    function (data) {
        alert(data);
    });
});

My Google Maps URL shows the JSON object when requesting it from the browser but not from using jQuery.

Alexander
  • 23,432
  • 11
  • 63
  • 73

3 Answers3

1

Use the Places-Library of the Maps-Javascript-API to request the service from a javascript-application.

<script type="text/javascript" 
      src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false">
</script>

<script  type="text/javascript">
/*<![CDATA[*/
$(document).ready(function () {
    new google.maps.places.PlacesService(document.createElement('div'))
     .textSearch({query:'KFC sydney'}, function(data){console.log(data);});
});
/*]]>*/
</script>
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
0

You need to pay more attention to your browser's JS console.

XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/textsearch/json?query=Kfc+sydney&sensor=true&key=AIzaSyD-jxenRCJipqw5Kg-HXQbRXUK8dHNFz3A. Origin http://jsbin.com is not allowed by Access-Control-Allow-Origin.

You are trying to violate the Same Origin Policy. Some work arounds are described in answers to this question.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • @user2082934 — No, there isn't "some piece of code" that will solve the problem. Read the links. – Quentin Feb 18 '13 at 12:56
0

See also: Google Maps V3 Geocoding Lookup using getJSON

FYI - if you are running a server-side language, such as PHP or JSP, you will be able to use the maps api url, as there are no javascript cross-domain issues with that approach, and you could write a page to effectively act as a proxy if you need to use javascript for handling the JSON.

Community
  • 1
  • 1
Raad
  • 4,540
  • 2
  • 24
  • 41