Geocoder icon indicating copy to clipboard operation
Geocoder copied to clipboard

[Pelias] Add codes to admin levels and support for localization and layers.

Open gbs opened this issue 4 years ago • 2 comments

Hi Jonathan,

We're moving towards using Pelias for geocoding, using the provider you wrote. We would like to use the codes for administrative regions as well, hence my pull request.

Examples to support the change:

Location before adding the admin level code

object(Camptoo\Geocoding\GeocoderLocation) {
	[protected] location => object(Geocoder\Model\Address) {
		[private] coordinates => object(Geocoder\Model\Coordinates) {
			[private] latitude => (float) 51.946443
			[private] longitude => (float) 4.509113
		}
		[private] bounds => object(Geocoder\Model\Bounds) {
			[private] south => (float) 52.332531
			[private] west => (float) 5.149456
			[private] north => (float) 51.64378
			[private] east => (float) 3.786154
		}
		[private] streetNumber => null
		[private] streetName => null
		[private] subLocality => null
		[private] locality => null
		[private] postalCode => null
		[private] adminLevels => object(Geocoder\Model\AdminLevelCollection) {
			[private] adminLevels => [
				(int) 1 => object(Geocoder\Model\AdminLevel) {
					[private] level => (int) 1
					[private] name => 'Zuid-Holland'
					[private] code => null
				},
				(int) 5 => object(Geocoder\Model\AdminLevel) {
					[private] level => (int) 5
					[private] name => 'Netherlands'
					[private] code => null
				}
			]
		}
		[private] country => object(Geocoder\Model\Country) {
			[private] name => 'Netherlands'
			[private] code => 'NLD'
		}
		[private] timezone => null
		[private] providedBy => 'pelias'
	}
}

Result from Pelias

image

Location after adding the admin level code

object(Camptoo\Geocoding\GeocoderLocation) {
	[protected] location => object(Geocoder\Model\Address) {
		[private] coordinates => object(Geocoder\Model\Coordinates) {
			[private] latitude => (float) 51.946443
			[private] longitude => (float) 4.509113
		}
		[private] bounds => object(Geocoder\Model\Bounds) {
			[private] south => (float) 52.332531
			[private] west => (float) 5.149456
			[private] north => (float) 51.64378
			[private] east => (float) 3.786154
		}
		[private] streetNumber => null
		[private] streetName => null
		[private] subLocality => null
		[private] locality => null
		[private] postalCode => null
		[private] adminLevels => object(Geocoder\Model\AdminLevelCollection) {
			[private] adminLevels => [
				(int) 1 => object(Geocoder\Model\AdminLevel) {
					[private] level => (int) 1
					[private] name => 'Zuid-Holland'
					[private] code => 'ZH'
				},
				(int) 5 => object(Geocoder\Model\AdminLevel) {
					[private] level => (int) 5
					[private] name => 'Netherlands'
					[private] code => 'NLD'
				}
			]
		}
		[private] country => object(Geocoder\Model\Country) {
			[private] name => 'Netherlands'
			[private] code => 'NLD'
		}
		[private] timezone => null
		[private] providedBy => 'pelias'
	}
}

Hope you like the addition.

Best regards

gbs avatar Jan 22 '21 09:01 gbs

Thanks @gbs !

I'll review it ASAP. Could you already make sure the formatting is correct (see https://github.styleci.io/analyses/Yj5KnG) ?

jbelien avatar Mar 30 '21 08:03 jbelien

Hi @jbelien,

The formatting is correct now. The build is failing, but I see this is on the master branch as well.

Since we're starting to use Pelias in more features, support for localization and layers was added. Also I improved the tests a bit by checking the query data from the request.

gbs avatar Mar 30 '21 10:03 gbs