user1141584
user1141584

Reputation: 619

Google Map API query for location

I m new to using Web services using JavaScript.

All I want is to get the bound value (northeast, southwest : latitude & longitude) from JSON through Google Maps API.

http://maps.googleapis.com/maps/api/geocode/json?address=chicago&sensor=true

I want to pass the value "Chicago" through HTML form.

But I should be having the above URL in a <script> . I m not sure about this. If yes, How can I call Chicago ? in the below tag through forms

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/geocode/json?address=chicago&sensor=true"></script>

I m new to this new kind of programming concept.

Any inputs would be helpful.

Thanks !!!

Upvotes: 0

Views: 1768

Answers (1)

Christofer Eliasson
Christofer Eliasson

Reputation: 33865

Unfortunately I don't believe you will be able to do that through a client-side script. The Geolocation API only support XML and JSON output. As you have to make a cross-domain request, both those formats are blocked by the browser for security reasons. For cross-domain requests you would have to use JSON-P, which is not supported.

You could set up a proxy within your own domain. Make a simple PHP, ASP.Net (or whatever server-side language you prefer) script that goes to Google, fetches the result, and send it back to you as JSON. Then your JavaScript could call your own proxy within your own domain, instead of calling Google straight away. A work around, to solve your problem with the same-origin policy.

Update

After reading through the documentation, you could use the JavaScript API, instead of the geolocation API. Hava a look at the documenation of the Geolocation service for the JavaScript API.

Upvotes: 1

Related Questions