Home > Blockchain >  Location field missing in place details request
Location field missing in place details request

Time:01-29

I'm having problems with google maps place details API.

this is my request:

https://maps.googleapis.com/maps/api/place/details/json?fields=name,rating,formatted_phone_number,formatted_address,geometry&place_id=PLACE_ID&key=API_KEY

I get the right response with all the fields I requested but when I try to read the value of location inside geometry I get this error:

TypeError: Cannot read property 'location' of undefined

How I try to extract the location parameter:

data["geometry"]["location"]

Any help would be appreciated, thanks!

{
   "html_attributions" : [],
   "result" : {
      "formatted_address" : "Level 1, 2 and 3, Overseas Passenger Terminal, Circular Quay W, The Rocks NSW 2000, Australia",
      "formatted_phone_number" : "(02) 9251 1188",
      "geometry" : {
         "location" : {
            "lat" : -33.85873230000001,
            "lng" : 151.2100055
         },
         "viewport" : {
            "northeast" : {
               "lat" : -33.8573990197085,
               "lng" : 151.2112270302915
            },
            "southwest" : {
               "lat" : -33.86009698029149,
               "lng" : 151.2085290697085
            }
         }
      },
      "name" : "Cruise Bar",
      "rating" : 4
   },
   "status" : "OK"
}

CodePudding user response:

data["geometry"]["location"]

probably needs to be

data["result"]["geometry"]["location"]

assuming data is the JSON parsed body.

  •  Tags:  
  • Related