Skip to content

Commit

Permalink
Better Instance Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
xolf committed Jan 14, 2017
1 parent 79a540e commit ffeaede
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# locationiq-php
Php Wrapper for https://locationiq.org

## Install
`composer require xolf/locationiq`

## Make first request
```php
$search = new \Xolf\LocationIQ\Search($apiKey);
$result = $search->get("Empire State Building");

// 40.7487727
$result[0]->lat;

// -73.9849336
$result[0]->lon;

// "node"
$result[0]->osm_type;

// "Empire State Building, 362, 5th Avenue, Diamond District, Manhattan, New York County, New York City, New York, 10035, United States of America"
$result[0]->osm_type;
```
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "xolf/locationiq",
"description": "Php Wrapper for https://locationiq.org",
"license": "MIT",
"authors": [
{
"name": "xolf",
Expand Down
15 changes: 13 additions & 2 deletions src/Geocoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ class Geocoding {
*/
protected $apiHandler;

public function __construct(ApiHandler $apiHandler)
/**
* Geocoding constructor.
* @param $api
* @throws Exception
*/
public function __construct($api)
{
$this->setApiHandler($apiHandler);
if(is_string($api)) {
$this->setApiHandler(ApiHandler::create($api));
} else if ($api instanceof ApiHandler) {
$this->setApiHandler($api);
} else {
throw new Exception("Unknown Api: ".var_export($api, true));
}
}

public function request() {
Expand Down

0 comments on commit ffeaede

Please sign in to comment.