简体   繁体   中英

Get Google Places ID from coordinates

I am looking for a way to find the PlaceID from a Google web request. I have several hundred addresses (ie coordinates) and I want to find a way to all enter them in a php script.

I am struggling with the API request for the place API. I have the following request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=50.096332,8.673130&radius=1&key=APIKEY

This returns the entire city of Frankfurt, but that's not what I am after. If I enter the address Oskar-Sommer-Strasse 7, Frankfurt am Main, Deutschland into the PlaceID finder on the Google Maps documentation site , I get the following result for the ID ChIJ-b9GgAUMvUcRYuYKJtGGlw4 .

I am now looking for a way to get this done. I've collected the coordinates using Google Maps API as well, so they should match (or at least that's what I thought).

Maybe I need to use some other request type?

Using the geocode api and sending a request to

https://maps.googleapis.com/maps/api/geocode/json?address=Oskar-Sommer-Strasse+7+%20Frankfurt%20am%20Main%20&component=Deutschland

returns (I'm assuming you want the place id field)

 {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "7",
               "short_name" : "7",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Oskar-Sommer-Straße",
               "short_name" : "Oskar-Sommer-Straße",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Frankfurt am Main Süd",
               "short_name" : "Frankfurt am Main Süd",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Frankfurt am Main",
               "short_name" : "Frankfurt am Main",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Darmstadt",
               "short_name" : "DA",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Hessen",
               "short_name" : "HE",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "60596",
               "short_name" : "60596",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Oskar-Sommer-Straße 7, 60596 Frankfurt am Main, Germany",
         "geometry" : {
            "location" : {
               "lat" : 50.09665,
               "lng" : 8.67299
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 50.0979989802915,
                  "lng" : 8.674338980291502
               },
               "southwest" : {
                  "lat" : 50.0953010197085,
                  "lng" : 8.671641019708497
               }
            }
         },
         "place_id" : "ChIJ-b9GgAUMvUcRYuYKJtGGlw4",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM