PHP code example of mehrdad-dadkhah / open-street-map-api

1. Go to this page and download the library: Download mehrdad-dadkhah/open-street-map-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mehrdad-dadkhah / open-street-map-api example snippets


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'

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);

        $osm->setBaseUrl('http://your-url.local');

$result = $locationService->setBaseUrl('CAN-SET-URL') // it's optional
        ->setPoint($lat, $long)
        ->setLanguage('fa')
        ->reverseLocation();

        use use MehrdadDadkhah\OSM\NominatimSearchPlaceService;
        .
        .
        .
        $nomiLocationService = new NominatimSearchPlaceService();
        $nomiLocationService->setLimit(1)
            ->enableAddressDetails()
            ->setSearchQuery($city->name) // name of city
            ->search();