1. Go to this page and download the library: Download cyrildewit/php-maps-urls 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/ */
cyrildewit / php-maps-urls example snippets
use CyrildeWit\MapsUrls\MapsUrl;
use CyrildeWit\MapsUrls\Actions\Directions;
use CyrildeWit\MapsUrls\Actions\Search;
use CyrildeWit\MapsUrls\Actions\StreetViewPanorama;
use CyrildeWit\MapsUrls\Enums\TravelMode;
use CyrildeWit\MapsUrls\Coordinates;
$searchUrl = MapsUrl::for(new Search(query: 'Rijksmuseum'));
// https://www.google.com/maps/search/?api=1&query=Rijksmuseum
$directionsUrl = MapsUrl::for(new Directions(
origin: 'Amsterdam',
destination: 'Utrecht',
travelMode: TravelMode::Bicycling,
));
// https://www.google.com/maps/dir/?api=1&origin=Amsterdam&destination=Utrecht&travelmode=bicycling
$panoramaUrl = MapsUrl::for(new StreetViewPanorama(
viewpoint: new Coordinates(48.857832, 2.295226),
));
// https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832%2C2.295226
use CyrildeWit\MapsUrls\MapsUrl;
use CyrildeWit\MapsUrls\Actions\Search;
$searchUrl = MapsUrl::for(new Search(query: 'Eindhoven, Nederland'));
// https://www.google.com/maps/search/?api=1&query=Eindhoven%2C+Nederland
use CyrildeWit\MapsUrls\UrlGenerator;
use CyrildeWit\MapsUrls\Actions\Directions;
use CyrildeWit\MapsUrls\Actions\Search;
$maps = new UrlGenerator(utmSource: 'my_app');
$searchUrl = $maps->generate(
new Search(query: 'Eindhoven'),
utmCampaign: 'search_request',
);
// https://www.google.com/maps/search/?api=1&query=Eindhoven&utm_source=my_app&utm_campaign=search_request
$directionsUrl = $maps->generate(
new Directions(origin: 'Eindhoven', destination: 'Utrecht'),
utmCampaign: 'directions_request',
);
// https://www.google.com/maps/dir/?api=1&origin=Eindhoven&destination=Utrecht&utm_source=my_app&utm_campaign=directions_request
use CyrildeWit\MapsUrls\Actions\Search;
use CyrildeWit\MapsUrls\Coordinates;
$action = new Search(query: new Coordinates(47.5951518, -122.3316393));
Coordinates::unchecked(48.857832, 542.295226);
use CyrildeWit\MapsUrls\Actions\Search;
$action = Search::fromArray([
'query' => 'Eindhoven, Nederland',
]);
use CyrildeWit\MapsUrls\Actions\Search;
use CyrildeWit\MapsUrls\Coordinates;
$action = new Search(
query: 'Eindhoven, Nederland',
queryPlaceId: 'ChIJn8N5VRvZxkcRmLlkgWTSmvM',
);
$action = new Search(query: new Coordinates(47.5951518, -122.3316393));
use CyrildeWit\MapsUrls\MapsUrl;
use CyrildeWit\MapsUrls\Actions\Search;
$searchUrl = MapsUrl::for(Search::fromArray([
'query' => 'Eindhoven, Nederland',
'query_place_id' => 'ChIJn8N5VRvZxkcRmLlkgWTSmvM',
]));
// https://www.google.com/maps/search/?api=1&query=Eindhoven%2C+Nederland&query_place_id=ChIJn8N5VRvZxkcRmLlkgWTSmvM
use CyrildeWit\MapsUrls\Actions\Directions;
use CyrildeWit\MapsUrls\Enums\Avoid;
use CyrildeWit\MapsUrls\Enums\DirectionAction;
use CyrildeWit\MapsUrls\Enums\TravelMode;
use CyrildeWit\MapsUrls\Coordinates;
$action = new Directions(
origin: 'Eindhoven, Nederland',
originPlaceId: 'ChIJn8N5VRvZxkcRmLlkgWTSmvM',
destination: 'Monnickendam, Nederland',
destinationPlaceId: 'ChIJTZfQeLgFxkcRQhAYGf9HbrU',
travelMode: TravelMode::Bicycling,
directionAction: DirectionAction::Navigate,
waypoints: ['Berlin,Germany', new Coordinates(48.8566, 2.3522)],
avoid: [Avoid::Tolls, Avoid::Ferries],
);
use CyrildeWit\MapsUrls\Actions\DisplayMap;
use CyrildeWit\MapsUrls\Enums\BaseMap;
use CyrildeWit\MapsUrls\Enums\Layer;
use CyrildeWit\MapsUrls\Coordinates;
$action = new DisplayMap(
center: new Coordinates(-33.8569, 151.2152),
zoom: 10,
baseMap: BaseMap::Satellite,
layer: Layer::Transit,
);