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.

1
  • The Google Maps API does not seem to allow cross-domain requests. Commented Feb 18, 2013 at 10:58

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

@user2082934 — No, there isn't "some piece of code" that will solve the problem. Read the links.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.