Skip to content

timstallmann/cartograf-geocoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cartograf/geocoder

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.