geocoder-php / Geocoder

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

Get type (and other privates) from nominatim #891

Closed Yamakasi closed 5 years ago

Yamakasi commented 6 years ago

I wonder if there is a way to get the type property from the address object and also the other info which is in a nominatim response object (and maybe others as well).

jbelien commented 6 years ago

Hello,

You can get the type property with getType() function. You can see all the properties available in Model/NominatimAddress.php.

Yamakasi commented 6 years ago

Hi,

Thanks! I would have believed the same but I don't get the options on an Address object so I got confused. I already fiddeled a little but with the code to see why. Can you give a small example maybe ? I can do a toArray() and such, getProvidedBy()...

jbelien commented 6 years ago

I don't have time to investigate this right now but I'll do it ASAP :)

Yamakasi commented 6 years ago

Thanks, I'm testing also using the Nominatim tests from the repo, let me know if you find something.

Should it work with registering the provider as well ?

/edit: I tested it out further and it seems to work, I only don't get the hints for getType() and the other ones where I first got an error, maybe that needs some investigation, I'm testing further.

jbelien commented 5 years ago

Hello again @Yamakasi ,

I checked and there is nothing wrong, as expected you can get the type property with getType() function.

Here is an example :

use Geocoder\Query\GeocodeQuery;

$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = \Geocoder\Provider\Nominatim\Nominatim::withOpenStreetMapServer($httpClient, $_SERVER['HTTP_USER_AGENT']);
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'en');

$result = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));

echo $result->first()->getType();
Nyholm commented 5 years ago

Thank you @jbelien. I see that you solved this issue.