Solved

Unable to resolve XML http request

Posted on 2016-09-28
4
105 Views
Last Modified: 2016-10-12
This is the error

perjs.html:1 XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8….1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.




This is the code...

<html>
  <head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script>
  $(document).ready(function(){
    $.getJSON('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM', function(myJSONResult){
      var myAddress = [];
      for (i = 0; i < myJSONResult.results.length; i++) {
        myAddress[i] = myJSONResult.results[i].formatted_address;
        alert(myAddress[i]);
      }
      
    });
  });

  </script>

  </head>
  <body>
  
  </body>
  </html>

Open in new window

0
Comment
Question by:yogesh byahatti
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 41821381
Why don't you make use of the places service?
To bad the places service need an instance of a map, but you don't have to use the map.
Have a look at this fiddle : https://jsfiddle.net/avanhalen/n5s4r3re/

I also updated the fiddle to show the markers on the map : https://jsfiddle.net/avanhalen/n5s4r3re/1/
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 41822030
you should do the request usin a server with PHP.
check this post for example :
https://www.experts-exchange.com/questions/28545160/PHP-variable-question.html
0
 

Author Comment

by:yogesh byahatti
ID: 41830477
Albert Van Halen

Thank you for the help. :)

But I am looking to parse the json data from the Google places api.
Please look at this

URL:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM


From this URL I want to retrieve Json data
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 250 total points
ID: 41830618
Well, you can.
In the example page I gave you I did it by showing markers on the map.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question