cartograf / geocoder
Barebones geocoder class using cUrl. Not a replacement for willdurand/geocoder
Requires
- php: ~5.5|~7.0
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2025-02-26 02:39:24 UTC
README
This is a bare-bones geocoding framework using cUrl to make http requests. I wrote it for myself as a utility class, mainly for geocoding from the command line.
It's intended to be easily extensible for custom geocoding APIs and to get out of the way as much as possible.
willdurand/geocoder
might be a better framework for you if you want something more robust or complex.
Install
Via Composer
$ composer require cartograf/geocoder
Usage
You'll need a class which extends the abstract Geocoder
base class and defines the following methods:
getQueryString(Address $address)
converts anAddress
into the portion of the query string which follows thebaseUrl
. Note that for now this needs to specify JSON output as well.getBaseUrl()
- defaults to$this->baseUrl
if that is set viasetBaseUrl()
getLatLngFromResult(\stdClass $result)
consumes the json-decoded result object and returns an object withlatitude
andlongitude
properties. Note that this is the final return value so you could add other properties as well if you need them.
Classes implementing MapQuest Nominatim (just set API key) and geocoding via an AWS EC2 instance of Geolytica's geocoder are included.
$ch = curl_init() or die("curl_init failed"); $geocoder = new Cartograf\Geocoder($ch); echo $geocoder->geoCode($address); curl_close($ch);
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Not yet implemented.
$ composer test
Contributing
Feel free to extend this and submit PRs! I welcome contributions.
Credits
License
The MIT License (MIT). Please see License File for more information.