Solved

Unable to resolve XML http request

Posted on 2016-09-28
4
62 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The viewer will learn how to dynamically set the form action using jQuery.
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)

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now