geocoder-php / Geocoder

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

locality and subLocality are mixed on providers #856

Closed Yamakasi closed 6 years ago

Yamakasi commented 6 years ago

It seems that locality and subLocality are mixed between providers, is this known ?

I have tested this between Google and OSM/OpenCase

OSM and OpenCase seem to be equal.


Geocoder\Model\AddressCollection Object
(
    [locations:Geocoder\Model\AddressCollection:private] => Array
        (
            [0] => Geocoder\Provider\GoogleMaps\Model\GoogleAddress Object
                (
                    [id:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => EjBWYW4gSGFzc2VsdGthZGUgOCwgNjIxMSBDQyBNYWFzdHJpY2h0LCBOZWRlcmxhbmQiGhIYChQKEgnh6Fxyx-nARxGdWJP4OJjXkBAI
                    [locationType:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => RANGE_INTERPOLATED
                    [resultType:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Array
                        (
                            [0] => street_address
                        )

                    [formattedAddress:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Van Hasseltkade 8, 6211 CC Maastricht, Netherlands
                    [streetAddress:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [intersection:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [political:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Netherlands
                    [colloquialArea:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [ward:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [neighborhood:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [premise:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [subpremise:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [naturalFeature:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [airport:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [park:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [pointOfInterest:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [establishment:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [subLocalityLevels:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                )

                        )

                    [coordinates:Geocoder\Model\Address:private] => Geocoder\Model\Coordinates Object
                        (
                            [latitude:Geocoder\Model\Coordinates:private] => 50.8538398
                            [longitude:Geocoder\Model\Coordinates:private] => 5.6937577
                        )

                    [bounds:Geocoder\Model\Address:private] => Geocoder\Model\Bounds Object
                        (
                            [south:Geocoder\Model\Bounds:private] => 50.852490819708
                            [west:Geocoder\Model\Bounds:private] => 5.6924087197085
                            [north:Geocoder\Model\Bounds:private] => 50.855188780291
                            [east:Geocoder\Model\Bounds:private] => 5.6951066802915
                        )

                    [streetNumber:Geocoder\Model\Address:private] => 8
                    [streetName:Geocoder\Model\Address:private] => Van Hasseltkade
                    [subLocality:Geocoder\Model\Address:private] => 
                    [locality:Geocoder\Model\Address:private] => Maastricht
                    [postalCode:Geocoder\Model\Address:private] => 6211 CC
                    [adminLevels:Geocoder\Model\Address:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                    [1] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 1
                                            [name:Geocoder\Model\AdminLevel:private] => Limburg
                                            [code:Geocoder\Model\AdminLevel:private] => LI
                                        )

                                    [2] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 2
                                            [name:Geocoder\Model\AdminLevel:private] => Maastricht
                                            [code:Geocoder\Model\AdminLevel:private] => Maastricht
                                        )

                                )

                        )

                    [country:Geocoder\Model\Address:private] => Geocoder\Model\Country Object
                        (
                            [name:Geocoder\Model\Country:private] => Netherlands
                            [code:Geocoder\Model\Country:private] => NL
                        )

                    [timezone:Geocoder\Model\Address:private] => 
                    [providedBy:Geocoder\Model\Address:private] => google_maps
                )

        )

)

///////////////////////// OSM ///////////////////////////////

Geocoder\Model\AddressCollection Object
(
    [locations:Geocoder\Model\AddressCollection:private] => Array
        (
            [0] => Geocoder\Provider\Nominatim\Model\NominatimAddress Object
                (
                    [attribution:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
                    [class:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => tourism
                    [displayName:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => Hotel Bigarré, 8, Van Hasseltkade, Boschstraatkwartier, Maastricht, Limburg, Nederland, 6211CC, Nederland
                    [osmType:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => node
                    [osmId:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => 3453439093
                    [type:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => hotel
                    [coordinates:Geocoder\Model\Address:private] => Geocoder\Model\Coordinates Object
                        (
                            [latitude:Geocoder\Model\Coordinates:private] => 50.853861
                            [longitude:Geocoder\Model\Coordinates:private] => 5.6935073
                        )

                    [bounds:Geocoder\Model\Address:private] => Geocoder\Model\Bounds Object
                        (
                            [south:Geocoder\Model\Bounds:private] => 50.853811
                            [west:Geocoder\Model\Bounds:private] => 5.6934573
                            [north:Geocoder\Model\Bounds:private] => 50.853911
                            [east:Geocoder\Model\Bounds:private] => 5.6935573
                        )

                    [streetNumber:Geocoder\Model\Address:private] => 8
                    [streetName:Geocoder\Model\Address:private] => Van Hasseltkade
                    [subLocality:Geocoder\Model\Address:private] => Maastricht
                    [locality:Geocoder\Model\Address:private] => Maastricht
                    [postalCode:Geocoder\Model\Address:private] => 6211CC
                    [adminLevels:Geocoder\Model\Address:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                    [1] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 1
                                            [name:Geocoder\Model\AdminLevel:private] => Limburg
                                            [code:Geocoder\Model\AdminLevel:private] => 
                                        )

                                )

                        )

                    [country:Geocoder\Model\Address:private] => Geocoder\Model\Country Object
                        (
                            [name:Geocoder\Model\Country:private] => Nederland
                            [code:Geocoder\Model\Country:private] => NL
                        )

                    [timezone:Geocoder\Model\Address:private] => 
                    [providedBy:Geocoder\Model\Address:private] => nominatim
                )

            [1] => Geocoder\Provider\Nominatim\Model\NominatimAddress Object
                (
                    [attribution:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
                    [class:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => place
                    [displayName:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => 8, Van Hasseltkade, Boschstraatkwartier, Maastricht, Limburg, Nederland, 6211CC, Nederland
                    [osmType:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => node
                    [osmId:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => 2808617293
                    [type:Geocoder\Provider\Nominatim\Model\NominatimAddress:private] => house
                    [coordinates:Geocoder\Model\Address:private] => Geocoder\Model\Coordinates Object
                        (
                            [latitude:Geocoder\Model\Coordinates:private] => 50.8536889
                            [longitude:Geocoder\Model\Coordinates:private] => 5.6935749
                        )

                    [bounds:Geocoder\Model\Address:private] => Geocoder\Model\Bounds Object
                        (
                            [south:Geocoder\Model\Bounds:private] => 50.8536389
                            [west:Geocoder\Model\Bounds:private] => 5.6935249
                            [north:Geocoder\Model\Bounds:private] => 50.8537389
                            [east:Geocoder\Model\Bounds:private] => 5.6936249
                        )

                    [streetNumber:Geocoder\Model\Address:private] => 8
                    [streetName:Geocoder\Model\Address:private] => Van Hasseltkade
                    [subLocality:Geocoder\Model\Address:private] => Maastricht
                    [locality:Geocoder\Model\Address:private] => Maastricht
                    [postalCode:Geocoder\Model\Address:private] => 6211CC
                    [adminLevels:Geocoder\Model\Address:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                    [1] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 1
                                            [name:Geocoder\Model\AdminLevel:private] => Limburg
                                            [code:Geocoder\Model\AdminLevel:private] => 
                                        )

                                )

                        )

                    [country:Geocoder\Model\Address:private] => Geocoder\Model\Country Object
                        (
                            [name:Geocoder\Model\Country:private] => Nederland
                            [code:Geocoder\Model\Country:private] => NL
                        )

                    [timezone:Geocoder\Model\Address:private] => 
                    [providedBy:Geocoder\Model\Address:private] => nominatim
                )

        )

)
Nyholm commented 6 years ago

Yeah, This is actually a "wont fix". It is the geocoder servers that decides that data to return and that is nothing we can change.

Yamakasi commented 6 years ago

Mhh, that is strange, you can make a default what you want to output by modifying the object you get back, I think that should be done at any time to get it lined up, that is what a lib can and should do.

Nyholm commented 6 years ago

If I geocode the address “foobar” and google server tells me “the subLocallity is xxx” and the OSM tells me “the subLocallity is yyy”, there is nothing the geocoder provider can do to “correct” this. It is simply an api client.

If you think I’m wrong, please provide a PR that fixes this issue and I’ll be happy to review it.

jbelien commented 6 years ago

I agree with @Nyholm here ; we rely on the information returned by the API. No reason to not "trust" what the API returns and I believe we shouldn't change (or mess) with what is returned by the API ; it will be confusing for the end users.

Yamakasi commented 6 years ago

I don't agree. If you aggregate results you need to make sure the results are the same format, they are not. The library is the layer where it should happen, not somwhere outside as the library already gives another output then the provider does by itself, it's not 1:1 already.

I see what I can do in a while as I don't need it now and went full OSM, but multiple resources should give the same format in result if the value exists.