mehrdad-dadkhah / open-street-map-api
Open Street Map (OSM) service to call and get results of APIs
Installs: 2 276
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 2
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
This package is auto-updated.
Last update: 2024-10-29 05:46:44 UTC
README
Open Street Map (OSM) service to call and get results of APIs.
Will add new services in future.
System requirements
only with >=7.0.0
Installation
composer require mehrdad-dadkhah/open-street-map-api
Usage
with coordinates option:
use MehrdadDadkhah\OSM\OSMRouteService; $osm = new OSMRouteService; $osm->addCoordinate(35.6998, 51.3310) ->addCoordinate(35.7581, 51.5087); echo $osm->getDuration()->getWithUnit(\MehrdadDadkhah\OSM\Types\Duration::MINUTE_UNIT); // or 'minute' echo $osm->getDistance()->getWithUnit(\MehrdadDadkhah\OSM\Types\Distance::KILOMETER_UNIT); // or 'kilometer'
with polyline option:
use MehrdadDadkhah\OSM\OSMRouteService; $osm = new OSMRouteService; $osm->setPolyline('ofp_Ik_vpAilAyu@te@g%60E'); echo $osm->getDuration()->getWithUnit(\MehrdadDadkhah\OSM\Types\Duration::MINUTE_UNIT); echo $osm->getDistance()->getWithUnit(\MehrdadDadkhah\OSM\Types\Distance::KILOMETER_UNIT);
If you have local osm-backend server, you can change base url by:
$osm->setBaseUrl('http://your-url.local');
Reverse location with osm
$result = $locationService->setBaseUrl('CAN-SET-URL') // it's optional ->setPoint($lat, $long) ->setLanguage('fa') ->reverseLocation();
Geocodeing
use use MehrdadDadkhah\OSM\NominatimSearchPlaceService; . . . $nomiLocationService = new NominatimSearchPlaceService(); $nomiLocationService->setLimit(1) ->enableAddressDetails() ->setSearchQuery($city->name) // name of city ->search();
Self hosted
If you want self host osrm-backend and notinimate can copy and custom docker-compose.yml in docker directory.
Acknowledgments
- Thanks to osrm-backend