geocoder-php / Geocoder

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

[Google] Administrative level 1 is defined twice #1173

Closed guitoon closed 1 year ago

guitoon commented 1 year ago

Hello, this fix remove double administrative area if they are the same. But I found an address on which Google give 2 different level 1 sublocality:

Rue de Pont-A-Migneloux, 6210 Wayaux, Belgique

image

I this case, the geocoder give me the same error Administrative level 1 is defined twice
How can I solve this issue?

jbelien commented 1 year ago

A PR (#1174) is ready that should solve this issue!

{
   "results" : [
      {
         "address_components" : [
            ...
            {
               "long_name" : "Wayaux",
               "short_name" : "Wayaux",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Les Bons Villers",
               "short_name" : "Les Bons Villers",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },,
            ...
         ],
         "formatted_address" : "Rue de Pont-à-Migneloux, 6210 Les Bons Villers, Belgique",
         ...
      }
   ],
   "status" : "OK"
}

In this case, it will combine the 2 sublocality_level_1 and return Wayaux / Les Bons Villers as SubLocality Level 1 (see tests).

guitoon commented 1 year ago

Nice, thank you

jbelien commented 1 year ago

Released: https://packagist.org/packages/geocoder-php/google-maps-provider#4.7.1

Stalinko commented 6 months ago

hey guys this bug is still hapenning.

Just try to reverse these coordinates:

        $lat = 22.63376;
        $lng = 88.4147;

It will throw Geocoder\Exception\InvalidArgument "Administrative level 3 is defined twice".

Because the address JSON contains:

            {
               "long_name" : "NDDM Ward No - 26",
               "short_name" : "NDDM Ward No - 26",
               "types" : 
               [
                  "administrative_area_level_3",
                  "political"
               ]
            },
            {
               "long_name" : "North 24 Parganas",
               "short_name" : "North 24 Parganas",
               "types" : 
               [
                  "administrative_area_level_3",
                  "political"
               ]
            },

And your fix doesn't help. Because the exception is thrown before withSubLocalityLevels() call. Any ideas how to fix it?

UPD in my local fork I've just removed this exception: https://github.com/lumiform/geocoder-php-common/commit/2ce26bd2465211bfceaf264fee998fc98b3c8a3b

It causes that the duplicate levels are ignored.