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.
Via Composer
$ composer require cartograf/geocoder
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);
Please see CHANGELOG for more information what has changed recently.
Not yet implemented.
$ composer test
Feel free to extend this and submit PRs! I welcome contributions.
The MIT License (MIT). Please see License File for more information.