PHP 7.0+ library providing a simple and minimalistic Geocoder interface with some basic implementations.
interface Geocoder {
/**
* Returns null when no result is found or when an error occurs.
* @return LatLongValue|null
*/
public function geocode( string $address );
}Geocoders using real geocoding services over HTTP:
GeoNamesGeocoderGoogleGeocoderNomatimGeocoder
Adapters:
GeocoderPhpAdapter- adapts to the popular PHP Geocoder library
Trivial implementations (great for testing):
InMemoryGeocoderNullGeocoderStubGeocoder
Decorators:
CoordinateFriendlyGeocoder
This library is based on code extracted from the Maps extension for MediaWiki.
To use the Simple Geocoder library in your project, simply add a dependency on jeroen/simple-geocoder
to your project's composer.json file. Here is a minimal example of a composer.json
file that just defines a dependency on Simple Geocoder 1.x:
{
"require": {
"jeroen/simple-geocoder": "~1.0"
}
}For development you need to have Docker and Docker-compose installed. Local PHP and Composer are not needed.
sudo apt-get install docker docker-compose
To pull in the project dependencies via Composer, run:
make composer install
You can run other Composer commands via make run, but at present this does not support argument flags.
If you need to execute such a command, you can do so in this format:
docker run --rm --interactive --tty --volume $PWD:/app -w /app\
--volume ~/.composer:/composer --user $(id -u):$(id -g) composer composer install -vvv
To run all CI checks, which includes PHPUnit tests, PHPCS style checks and coverage tag validation, run:
make
To run just the PHPUnit tests run
make test
To run only a subset of PHPUnit tests or otherwise pass flags to PHPUnit, run
docker-compose run --rm app ./vendor/bin/phpunit --filter SomeClassNameOrFilter
- Updated attribution
- Installation with FileFetcher 6.x is now allowed
- Added
GeocoderPhpAdapterthat allows using the popular PHP Geocoder library - Installation with DataValues Geo 4.x is now allowed
- Installation with DataValues Geo 3.x is now allowed
Initial release as standalone component with
- FileFetcher based geocoders:
GeoNamesGeocoder,GoogleGeocoder,NomatimGeocoder - Trivial implementations:
InMemoryGeocoder,NullGeocoder,StubGeocoder - Decorators:
CoordinateFriendlyGeocoder

