-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dbfebb6
Showing
10 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 kolirt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Laravel Openstreetmap | ||
|
||
## Installation | ||
``` | ||
$ composer require kolirt/laravel-openstreetmap | ||
``` | ||
``` | ||
$ php artisan openstreetmap:install | ||
``` | ||
|
||
## Methods | ||
|
||
#### Details by place_id | ||
``` | ||
Kolirt\Openstreetmap\Facade\Openstreetmap::details(int $place_id); | ||
``` | ||
|
||
#### Reverse | ||
``` | ||
Kolirt\Openstreetmap\Facade\Openstreetmap::reverse(float $lat, float $lng); | ||
``` | ||
|
||
#### Search | ||
``` | ||
Kolirt\Openstreetmap\Facade\Openstreetmap::search(string $q, int $limit = 10); | ||
``` | ||
|
||
#### Search by params | ||
``` | ||
Kolirt\Openstreetmap\Facade\Openstreetmap::searchByParams($streetname = null, | ||
$housenumber = null, | ||
$city = null, | ||
$state = null, | ||
$country = null, | ||
$postalcode = null, | ||
int $limit = 10); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "kolirt/laravel-openstreetmap", | ||
"description": "Package for openstreetmap.org", | ||
"keywords": ["laravel", "openstreetmap", "map"], | ||
"license": "MIT", | ||
"version": "1.0.3", | ||
"authors": [ | ||
{ | ||
"name": "kolirt" | ||
} | ||
], | ||
"require": { | ||
"guzzlehttp/guzzle": "> 6.0.0" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"src/helpers.php" | ||
], | ||
"psr-4": { | ||
"Kolirt\\Openstreetmap\\": "src" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Kolirt\\Openstreetmap\\ServiceProvider" | ||
], | ||
"aliases": { | ||
"Openstreetmap": "Kolirt\\Openstreetmap\\Facade\\Openstreetmap" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'lang' => 'en', | ||
'timeout' => 1 | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Kolirt\Openstreetmap\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class InstallCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'openstreetmap:install'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Instalation Openstreetmap package'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->call('vendor:publish', ['--provider' => 'Kolirt\\Openstreetmap\\ServiceProvider']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Kolirt\Openstreetmap\Facade; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* @method static object|null details(int $place_id) | ||
* @method static object|null reverse(float $lat, float $lng) | ||
* @method static array|null search(string $q, int $limit = 10) | ||
* @method static array|null searchByParams($streetname = null, $housenumber = null, $city = null, $state = null, $country = null, $postalcode = null, int $limit = 10) | ||
*/ | ||
class Openstreetmap extends Facade | ||
{ | ||
|
||
protected static function getFacadeAccessor() | ||
{ | ||
return 'openstreetmap'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Kolirt\Openstreetmap; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class Openstreetmap | ||
{ | ||
|
||
private $client; | ||
private $api = 'https://nominatim.openstreetmap.org/'; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client([ | ||
'base_uri' => $this->api, | ||
'timeout' => config('openstreetmap.timeout', 1) | ||
]); | ||
} | ||
|
||
public function details(int $place_id) | ||
{ | ||
try { | ||
$request = $this->client->get('details', [ | ||
'query' => [ | ||
'place_id' => $place_id, | ||
'format' => 'json', | ||
'accept-language' => config('openstreetmap.lang') | ||
] | ||
]); | ||
|
||
if ($request->getStatusCode() == 200) { | ||
return json_decode($request->getBody()->getContents()); | ||
} | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public function reverse(float $lat, float $lng) | ||
{ | ||
try { | ||
$request = $this->client->get('reverse', [ | ||
'query' => [ | ||
'lat' => $lat, | ||
'lon' => $lng, | ||
'format' => 'json', | ||
'accept-language' => config('openstreetmap.lang') | ||
] | ||
]); | ||
|
||
if ($request->getStatusCode() == 200) { | ||
$result = json_decode($request->getBody()->getContents()); | ||
|
||
if (is_null($result->error ?? null)) { | ||
return $result; | ||
} | ||
|
||
return null; | ||
} | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public function search(string $q, int $limit = 10) | ||
{ | ||
try { | ||
$request = $this->client->get('search', [ | ||
'query' => [ | ||
'q' => $q, | ||
'polygon_geojson' => 1, | ||
'limit' => $limit, | ||
'format' => 'json', | ||
'accept-language' => config('openstreetmap.lang') | ||
] | ||
]); | ||
|
||
if ($request->getStatusCode() == 200) { | ||
return json_decode($request->getBody()->getContents()); | ||
} | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public function searchByParams($streetname = null, $housenumber = null, $city = null, $state = null, $country = null, $postalcode = null, int $limit = 10) | ||
{ | ||
try { | ||
$request = $this->client->get('search', [ | ||
'query' => [ | ||
'street' => $housenumber . ' ' . $streetname, | ||
'city' => $city, | ||
'state' => $state, | ||
'country' => $country, | ||
'postalcode' => $postalcode, | ||
'polygon_geojson' => 1, | ||
'limit' => $limit, | ||
'format' => 'json', | ||
'accept-language' => config('openstreetmap.lang') | ||
] | ||
]); | ||
|
||
if ($request->getStatusCode() == 200) { | ||
return json_decode($request->getBody()->getContents()); | ||
} | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Kolirt\Openstreetmap; | ||
|
||
use Illuminate\Support\ServiceProvider as BaseServiceProvider; | ||
|
||
class ServiceProvider extends BaseServiceProvider | ||
{ | ||
protected $commands = [ | ||
Commands\InstallCommand::class | ||
]; | ||
|
||
/** | ||
* Bootstrap any application services. | ||
*/ | ||
public function boot() | ||
{ | ||
$this->mergeConfigFrom(__DIR__ . '/../config/openstreetmap.php', 'openstreetmap'); | ||
|
||
$this->publishes([ | ||
__DIR__ . '/../config/openstreetmap.php' => config_path('openstreetmap.php') | ||
]); | ||
} | ||
|
||
/** | ||
* Register any application services. | ||
*/ | ||
public function register() | ||
{ | ||
$this->commands($this->commands); | ||
|
||
app()->bind('openstreetmap', function(){ | ||
return new Openstreetmap(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
|