mehrdad-dadkhah/open-street-map-api

There is no license information available for the latest version (1.0.0) of this package.

Open Street Map (OSM) service to call and get results of APIs

1.0.0 2019-09-03 11:06 UTC

This package is auto-updated.

Last update: 2024-11-29 06:01:24 UTC


README

Packagist Version

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

Uses: