Download the PHP package cyrildewit/php-maps-urls without Composer
On this page you can find all versions of the php package cyrildewit/php-maps-urls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cyrildewit/php-maps-urls
More information about cyrildewit/php-maps-urls
Files in cyrildewit/php-maps-urls
Package php-maps-urls
Short Description Generate URLs for the Google Maps URLs API
License Apache-2.0
Homepage https://github.com/cyrildewit/php-maps-urls
Informations about the package php-maps-urls
PHP Google Maps URLs
This package allows you to build URLs for the Google Maps URLs API.
Here's a quick example:
Overview
This package provides a convenient way to generate URLs for the Google Maps URLs API. Each action has its own abstraction that can be used to generate a URL. For more information about this API, head over to the Google Maps URLs API documentation.
Documentation
Table of contents
- Getting Started
- Requirements
- Installation
- Usage
- Generating a URL
- Actions
- Search
- Directions
- Displaying a map
- Display a Street View panorama
- Credits
- License
Getting Started
Requirements
This package requires PHP 7.4+.
Version information
| Version | Status | PHP Version |
|---|---|---|
| ^1.0 | Active support | >= 7.4.0 |
Installation
You can install this package via Composer using:
Usage
Generating a URL
The CyrildeWit\MapsUrls\UrlGenerator class is responsible for generation the URLs. The constructor accepts an instance of an action class. Action classes extends CyrildeWit\MapsUrls\Actions\AbstractAction.
Output $searchUrl: https://www.google.com/maps/search/?api=1&query=Eindhoven,%20Nederland
Actions
The Google Maps URLs API allows you to generate a URL that performs a certain actions. These actions can be configured by using one of the provided action classes.
Search
From the official documentation: "Launch a Google Map that displays a pin for a specific place, or perform a general search and launch a map to display the results."
Query
To set the query of the search action, you can call the setQuery(string $query) method.
The query parameter may also consist of latitude/longitude coordinates. You can add them together yourself or make use of the setCoordinates(float $latitude, float $longitude) method.
Query Place ID
If you want to specify the optional place ID for a search action, you can add it using the setQueryPlaceId(string $placeId) method.
Magic make constructor
To instantiate a search action with initial query parameters values, you can make use of the magic SearchAction::make(array $options) method.
Directions
From the official documentation: "Request directions and launch Google Maps with the results."
Origin
The origin can be defined using method setOrigin(string $origin).
Origin Place ID
The origin place ID can be defined using method setOriginPlaceId(string $placeId).
Destination
The destination can be defined using method setDestination(string $destination).
Destination Place ID
The destination place ID can be defined using method setDestinationPlaceId(string $placeId).
Travel Mode
The travel mode can be defined using method setTravelMode(string $travelmode). The valid options are:
drivingwalkingbicyclingtransit
These options can be referenced using the constants defined in CyrildeWit\MapsUrls\Enums\TravelMode.
Example:
The CyrildeWit\MapsUrls\Exceptions\InvalidTravelMode exception will be thrown when an invalid travel mode is provided.
Direction Action
The direction action can be defined using method setDirectionAction(string $directionAction). The only valid option is navigate. You can use the NAVIGATE constant in DirectionAction class for convenience.
The CyrildeWit\MapsUrls\Exceptions\InvalidDirectionAction exception will be thrown when an invalid direction action is provided.
Waypoints
The waypoints can be defined using method setWaypoints(array $waypoints).
Waypoint place IDs
Waypoint place IDs can be defined using method setWaypointPlaceIds(array $placeIds).
Magic make constructor
To instantiate a directions action with initial query parameters values, you can make use of the magic DirectionsAction::make(array $options) method.
Displaying a map
From the official documentation: "Launch Google Maps with no markers or directions."
Map action
The map_action query parameter is required and is therefore added by default with value map.
Center
The center of the map can be defined by setting the coordinates using method setCenter(float $latitude, float $longitude).
Zoom
The zoom level of the map can be defined by using method setZoom(int $zoom).
Base Map
The base map can be defined using method setBaseMap(string $baseMap). The valid options are:
nonetrafficbicycling
These options can be referenced using the constants defined in CyrildeWit\MapsUrls\Enums\TravelMode.
Example:
The CyrildeWit\MapsUrls\Exceptions\InvalidBaseMap exception will be thrown when an invalid base map is provided.
Layer
The layer can be defined using method setLayer(string $layer). The valid options are:
nonetransittrafficbicycling
These options can be referenced using the constants defined in CyrildeWit\MapsUrls\Enums\Layer.
Example:
The CyrildeWit\MapsUrls\Exceptions\InvalidLayer exception will be thrown when an invalid layer is provided.
Magic make constructor
To instantiate a display street view panorama action with initial query parameters values, you can make use of the magic DirectionsAction::make(array $options) method.
Display a Street View panorama
From the official documentation: "Launch an interactive panorama image."
Map action
The map_action query parameter is required and is therefore added by default with value pano.
Viewpoint
The viewpoint can be defined using method setViewpoint(float $latitude, float $longitude).
Panorama ID
The panorama ID can be defined using method setPanoramaId(string $id).
Heading
The heading can be defined using method setHeading(int $degrees). Only values from 180 to 360 degrees are expected.
The CyrildeWit\MapsUrls\Exceptions\InvalidHeading exception will be thrown when an invalid heading is provided.
Pitch
The pitch can be defined using method setPitch(int $degrees). Only values from -90 to 80 degrees are expected.
The CyrildeWit\MapsUrls\Exceptions\InvalidPitch exception will be thrown when an invalid heading is provided.
Fov
The pitch can be defined using method setFov(int $degrees). Only values from -10 to 100 degrees are expected.
The CyrildeWit\MapsUrls\Exceptions\InvalidFov exception will be thrown when an invalid heading is provided.
Magic make constructor
To instantiate a display street view panorama action with initial query parameters values, you can make use of the magic DirectionsAction::make(array $options) method.
Credits
- Cyril de Wit - Creator - cyrildewit
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.