简体   繁体   中英

for http request to google maps API

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM