Upon receiving the JSON response from the Google Maps API stored in a variable named 'obj', I noticed that alerting obj.name returns "Pancakes on the Rocks". To access the icon, I can use obj.icon. However, I am struggling to retrieve separate values for latitude (lat) and longitude (lng). When I alert obj.geometry.location, it displays as (-33.87054,151.198815) together. What is the best way to extract these values individually? Your suggestions are greatly appreciated. Thank you.
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.87054,
"lng" : 151.198815
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "c71365287e7606bd21a3311d21fda087830b7813",
"name" : "Pancakes on the Rocks",
"opening_hours" : {
"open_now" : true
},
"photos" : [
...
function createMarkers(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createResultMarker(results[i]);
}
}
}
function createResultMarker(obj) {
alert('title: ' + obj.name); // Displays correct name.
alert(obj.geometry.location);
alert(obj.geometry.location.lat);
distance = getDistanceFromLatLonInKm(init_lat, init_lng, obj.geometry.location.lat, obj.geometry.location.lng);
}