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

JamieA

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"
}

,

Tanmay Delhikar

Use below code to parse your json to get latitude and longitude:

var jsonArr = JSON.parse(body);
var x=jsonArr.results;
var y=x[0];
var latitude = y.geometry.location.lat;
var longitude = y.geometry.location.lng

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Longitude and Latitude from Google Maps Api JSON?

From Dev

How to set latitude/longitude from bundle to Google Maps

From Dev

How get latitude and longitude from an Android listview and put it in google maps?

From Dev

How to get Latitude and Longitude Bounds from Google Maps x y and zoom parameters

From Dev

How to get the Latitude, Longitude at a X distance from the specified Point(Lat,Lng) in Android Google Maps

From Dev

How to get Latitude and Longitude Bounds from Google Maps x y and zoom parameters

From Dev

How to get array of latitude and longitude array from google maps direction api

From Dev

REGEX: Extract latitude and longitude from Google Maps static image url

From Dev

Sending URL to Google Maps from PHP with latitude and longitude values

From Dev

google maps how to add marker if I know the latitude and longitude

From Dev

How to obtain Latitude and Longitude when clicking on a rectangle in Google Maps?

From Dev

google maps how to add marker if I know the latitude and longitude

From Dev

How to obtain Latitude and Longitude when clicking on a rectangle in Google Maps?

From Dev

Google Maps - How to add a number to a latitude/longitude to change the coordinate

From Dev

Using variables for longitude and latitude with google maps api

From Dev

finding latitude and longitude between a route in google maps

From Dev

Check if a latitude and longitude is within a circle google maps

From Dev

Displaying latitude and longitude of Google Maps marker in InfoWindow

From Dev

Removing marker by latitude/longitude in google maps

From Dev

focusing on google maps api according to latitude and longitude

From Dev

Send latitude-longitude argument to Google Maps

From Dev

Parsing Google Maps API for Latitude and Longitude (Bash)

From Dev

Attach latitude and longitude to markers in google maps

From Dev

Get latitude and longitude from json

From Java

How to get address location from latitude and longitude in Google Map.?

From Dev

How do hide latitude and longitude from pin on google map

From Dev

How to get place_id from longitude and latitude in google Map?

From Dev

How to show received latitude/longitude from server on google map?

From Dev

How to get latitude and longitude from google place map?

Related Related

  1. 1

    Longitude and Latitude from Google Maps Api JSON?

  2. 2

    How to set latitude/longitude from bundle to Google Maps

  3. 3

    How get latitude and longitude from an Android listview and put it in google maps?

  4. 4

    How to get Latitude and Longitude Bounds from Google Maps x y and zoom parameters

  5. 5

    How to get the Latitude, Longitude at a X distance from the specified Point(Lat,Lng) in Android Google Maps

  6. 6

    How to get Latitude and Longitude Bounds from Google Maps x y and zoom parameters

  7. 7

    How to get array of latitude and longitude array from google maps direction api

  8. 8

    REGEX: Extract latitude and longitude from Google Maps static image url

  9. 9

    Sending URL to Google Maps from PHP with latitude and longitude values

  10. 10

    google maps how to add marker if I know the latitude and longitude

  11. 11

    How to obtain Latitude and Longitude when clicking on a rectangle in Google Maps?

  12. 12

    google maps how to add marker if I know the latitude and longitude

  13. 13

    How to obtain Latitude and Longitude when clicking on a rectangle in Google Maps?

  14. 14

    Google Maps - How to add a number to a latitude/longitude to change the coordinate

  15. 15

    Using variables for longitude and latitude with google maps api

  16. 16

    finding latitude and longitude between a route in google maps

  17. 17

    Check if a latitude and longitude is within a circle google maps

  18. 18

    Displaying latitude and longitude of Google Maps marker in InfoWindow

  19. 19

    Removing marker by latitude/longitude in google maps

  20. 20

    focusing on google maps api according to latitude and longitude

  21. 21

    Send latitude-longitude argument to Google Maps

  22. 22

    Parsing Google Maps API for Latitude and Longitude (Bash)

  23. 23

    Attach latitude and longitude to markers in google maps

  24. 24

    Get latitude and longitude from json

  25. 25

    How to get address location from latitude and longitude in Google Map.?

  26. 26

    How do hide latitude and longitude from pin on google map

  27. 27

    How to get place_id from longitude and latitude in google Map?

  28. 28

    How to show received latitude/longitude from server on google map?

  29. 29

    How to get latitude and longitude from google place map?

HotTag

Archive