geocoder-php / Geocoder

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

Location type for Google map provider #1126

Closed degorych closed 3 years ago

degorych commented 3 years ago

$geocoder->geocodeQuery(GeocodeQuery::create($address)) can return approximate coordinates if street or street number not found. For example: $geocoder->geocodeQuery(GeocodeQuery::create('Кропивницький вул. Велика Перспективна, 36'))->getCoordinates()->toArray() // Place found $geocoder->geocodeQuery(GeocodeQuery::create('Кропивницький вул. Велика Перспективна, 136'))->getCoordinates()->toArray() // Approximate street center, because house №136 does not exist $geocoder->geocodeQuery(GeocodeQuery::create('Кропивницький вул. Акинфеева, 136'))->getCoordinates()->toArray() // Approximate city center, because street "Акинфеева" does not exist.

In all these cases, I get the coordinates, but only in the first version the coordinates are valid (exact). Google map api has location_type in response body. The provider has a locationType, but this is a private property. Can you add a getter to this property to determine the precision of the address? This is very important, because users enter street and street number and they can make mistake.

jbelien commented 3 years ago

GoogleMaps provider already has a getLocationType() function to retrieve the location type.

https://github.com/geocoder-php/Geocoder/blob/1714d61578ea4881c8d481feae4e214e902095e4/src/Provider/GoogleMaps/Model/GoogleAddress.php#L163-L166