geocoder-php / Geocoder

The most featured Geocoder library written in PHP.
https://geocoder-php.org
MIT License
3.95k stars 519 forks source link

Gecode not returnong result from zipcode 17000 #1048

Closed ahmed-bhs closed 4 years ago

ahmed-bhs commented 4 years ago

This is really weird, I'm using https://github.com/geocoder-php/Geocoder library, and unfortunately I'm not getting the city name for a zip code equal to 17000. I'm supposed to get "La Rochelle" as city. This is my source code:

$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps(
         (new \Http\Adapter\Guzzle6\Client()),
         'France', $this->googleMapApiKey
     );
     $geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
     $geocoder->geocodeQuery(GeocodeQuery::create('17000, France'));;

This a dump of the result I'm getting:

GeoService.php on line 79:
AddressCollection {#4709 ▼
  -locations: array:1 [▼
    0 => GoogleAddress {#4707 ▼
      -id: "ChIJdT0lyYNTAUgRsFiFqpXTBRw"
      -locationType: "APPROXIMATE"
      -resultType: array:1 [▶]
      -formattedAddress: "17000, France"
      -streetAddress: null
      -intersection: null
      -political: "France"
      -colloquialArea: null
      -ward: null
      -neighborhood: null
      -premise: null
      -subpremise: null
      -naturalFeature: null
      -airport: null
      -park: null
      -pointOfInterest: null
      -establishment: null
      -subLocalityLevels: AdminLevelCollection {#4712 ▼
        -adminLevels: []
      }
      -partialMatch: false
      -coordinates: Coordinates {#4689 ▼
        -latitude: 46.1600767
        -longitude: -1.1774721
      }
      -bounds: Bounds {#4690 ▼
        -south: 46.1331208
        -west: -1.2417438
        -north: 46.1910004
        -east: -1.1113177
      }
      -streetNumber: null
      -streetName: null
      -subLocality: null
      -locality: null
      -postalCode: "17000"
      -adminLevels: AdminLevelCollection {#4708 ▼
        -adminLevels: array:1 [▼
          1 => AdminLevel {#4701 ▼
            -level: 1
            -name: "Nouvelle-Aquitaine"
            -code: "Nouvelle-Aquitaine"
          }
        ]
      }
      -country: Country {#4704 ▼
        -name: "France"
        -code: "FR"
      }
      -timezone: null
      -providedBy: "google_maps"
    }
  ]

By the way the city name should be stored under Locality proprity. Any help would be appreciated.

jbelien commented 4 years ago

Hello @ahmed-bhs,

Could you give use the raw response from Google Maps API (so we can compare and detect where the issue exactly is) ?

ahmed-bhs commented 4 years ago

Hey @jbelien thank for your answer, ther's is it :


{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "17000",
               "short_name" : "17000",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Nouvelle-Aquitaine",
               "short_name" : "Nouvelle-Aquitaine",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "France",
               "short_name" : "FR",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "17000, France",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 46.19100040000001,
                  "lng" : -1.1113177
               },
               "southwest" : {
                  "lat" : 46.1331208,
                  "lng" : -1.2417438
               }
            },
            "location" : {
               "lat" : 46.1600767,
               "lng" : -1.1774721
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 46.19100040000001,
                  "lng" : -1.1113177
               },
               "southwest" : {
                  "lat" : 46.1331208,
                  "lng" : -1.2417438
               }
            }
         },
         "place_id" : "ChIJdT0lyYNTAUgRsFiFqpXTBRw",
         "types" : [ "postal_code" ]
      }
   ],
   "status" : "OK"
}

This is my get http url: https://maps.googleapis.com/maps/api/geocode/json?address=17000,%20France&key=API_KEY

jbelien commented 4 years ago

Thanks!

As you can see, there is no mention of "La Rochelle" in Google Maps API response. We can, of course, only extract what the API returns.

ahmed-bhs commented 4 years ago

@jbelien just for curiosity, do you have any idea why google map does not return city name for some zipcodes ?

jbelien commented 4 years ago

@ahmed-bhs Unfortunately, no, I have no idea.