Google Geocoding API - JSON
Parse JSON data using jQuery.getJSON()
Now, we will primarily focus here on getting the values for the keys:
formatted_address
, lat
andlng
. Where,formatted_address
is a string containing the human-readable address of this location.lat
is the geocoded latitude value.lng
is the geocoded longitude value.
Now, we can get these values using jQuery like this:
1
2
3
4
5
6
7
8
9
10
11
12
| var geocodingAPI = "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true" ; $.getJSON(geocodingAPI, function (json) { var address = json.results[0].formatted_address; console.log( 'Address : ' , address); var latitude = json.results[0].geometry.location.lat; console.log( 'Latitude : ' , latitude); var longitude = json.results[0].geometry.location.lng; console.log( 'Longitude : ' , longitude); });
|
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。