/Roadlength

Library to calc distance between location by road

Primary LanguagePHPGNU General Public License v3.0GPL-3.0

MvRoadlength

This API is to calc distance between two points by road.

Install

composer require mv/roadlength

Examples

With postal address

use Mv\RoadLength\Api\HereApi;
use Mv\RoadLength\Geo\Location;
use Mv\RoadLength\Geo\Distance;

$hereApi = new HereApi('---Your HERE API KEY---');

$origin = Location::createByAddress('mairie de hyeres 83400 HYERES', $hereApi);
$destination = Location::createByAddress('mairie de sollies-toucas 83210 SOLLIES-TOUCAS', $hereApi);

$distance = new Distance($hereApi);
$distance->setStartLocation($origin);
$distance->setEndLocation($destination);

$distanceInMeters = $distance->getDistance();

With geoloc coordinates

use Mv\RoadLength\Api\HereApi;
use Mv\RoadLength\Geo\Location;
use Mv\RoadLength\Geo\Distance;

$hereApi = new HereApi('---Your HERE API KEY---');

$origin = Location::createByCoords(43.119840, 6.129904);
$destination = Location::createByCoords(43.206368, 6.026157);

$distance = new Distance($hereApi);
$distance->setStartLocation($origin);
$distance->setEndLocation($destination);

$distanceInMeters = $distance->getDistance();

Enjoy it!

To be continued...