cartograf/geocoder

Barebones geocoder class using cUrl. Not a replacement for willdurand/geocoder

1.0.2 2017-10-05 19:35 UTC

This package is not auto-updated.

Last update: 2024-04-23 22:25:42 UTC


README

Latest Version on Packagist Software License Total Downloads

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 an Address into the portion of the query string which follows the baseUrl. Note that for now this needs to specify JSON output as well.
  • getBaseUrl() - defaults to $this->baseUrl if that is set via setBaseUrl()
  • getLatLngFromResult(\stdClass $result) consumes the json-decoded result object and returns an object with latitude and longitude 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.