Saturday, 13 May 2017

How to access latitude and longitude from Google Maps JSON response in NodeJS

How can I extract the lat and lng from the location object in this JSON response from Google maps? I tried response.body.results[0].geometry.location.lat but it says ReferenceError: results is not defined. This is the body of the response:

    {
html_attributions: [ ],
results: [
{
geometry: {
location: {
lat: 48.8348765,
lng: 2.5617076
},
viewport: {
northeast: {
lat: 48.8361706302915,
lng: 2.563131680291503
},
southwest: {
lat: 48.8334726697085,
lng: 2.560433719708499
}
}
},
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
id: "2f85a7178e9e4d6179d64cba989050f10a8cc820",
name: "McDonald's",
opening_hours: {
open_now: true,
weekday_text: [ ]
},
photos: [
{
height: 5312,
html_attributions: [
"<a href="https://maps.google.com/maps/contrib/102946777538271968493/photos">marianne &amp; guillaume PATRY</a>"
],
photo_reference: "CmRYAAAAJEw36IIqxn8QlGJs5uHBdP4jUIzdHTtb-sTWeqSbvRov_UJy5N8xKShGBp_6J4AAx2_yIOtFUYrUXARvcsF2CNM1CYqnRi_02e8GyF2zXH8addeQrokHG3TrbmbJTK39EhDAVnpiTfD_7jKirlM2mKuEGhTqgn0Zhi7dZKU9V0N0akGVrTqaWQ",
width: 2988
}
],
place_id: "ChIJCdJ4JG0O5kcREQBADVbUgUM",
price_level: 1,
rating: 3.4,
reference: "CmRRAAAA8WdPwuDOgyz88Rmi2E06G3KC6sFnP0S_1Yy0eblRSUUAiujB7IHi9HKECdfVr4r1almTj8a5Jn3hcUcBwR_Bi6H1Lk3ioUCLuKwJJqOzlVX_iTttxseWVgCa7hKAjfQXEhDHALMNJdsEdjB9vOHj0U9NGhQYBsbSMSyysXYxhvmBQsO9QMIyhw",
scope: "GOOGLE",
types: [
"restaurant",
"food",
"point_of_interest",
"establishment"
],
vicinity: "1 Avenue du Fort, Noisy-le-Grand"
}

,



via JamieA

No comments:

Post a Comment