1
votes

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=(API_KEY)

Google API page said the above URL is the http request and a json string is the response. How do I do this in javascript? I tried using the XMLHTTPrequest object at first but later found out it doesn't work between different domains. I then tried using a callback function with

where function myCallbackFunction(expectedJSONstring){ alert(expectedJSONstring) } doesn't get called.

1
If you want to do this from javascript, why aren't you using the Google Maps Javascript API v3 geocoding service?geocodezip

1 Answers

0
votes

The recommended way to do this is in JavaScript is through the Geocoding service that geocodezip mentioned. The main reason for doing this is that quota becomes per-user rather than per-key.

If you still want to do this through JavaScript then something like jQuery's $.getJSON() will do cross-domain requests of JSON payloads.

You really should use the Geocoding service though. It's much nicer. Really. Go on. Use it.