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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-maps-urls

PHP Google Maps URLs

Generate URLs for the Google Maps URLs API


Latest Version Total Downloads GitHub Actions Workflow Status License Coverage


Table of Contents 1. [Introduction](#introduction) 2. [Getting Started](#getting-started) - [Version Compatibility](#version-compatibility) - [Installation](#installation) 3. [Usage](#usage) - [Generating a URL](#generating-a-url) - [Campaign tracking](#campaign-tracking) - [Coordinates](#coordinates) - [Actions](#actions) - [Creating an action from an array](#creating-an-action-from-an-array) - [Search](#search) - [Directions](#directions) - [DisplayMap](#displaymap) - [StreetViewPanorama](#streetviewpanorama) 4. [Changelog](#changelog) 5. [Contributing](#contributing) 6. [Credits](#credits) 7. [License](#license)

Introduction

PHP Google Maps URLs builds URLs for the Google Maps URLs API. Every action the API supports has its own class. You construct one and hand it to MapsUrl::for(), which gives you a string back.

The package only builds the URL string. It sends no HTTP request, and Google does not require an API key for Maps URLs. Opening the result launches the Google Maps app on Android and iOS when the app is installed, and a browser everywhere else.

Quick Example

Once installed, generating a URL looks like this:

Key Features

Getting Started

Version Compatibility

Package Version PHP
2.x 8.5+
1.x 7.4+

Installation

First, you need to install the package via Composer:

Usage

Generating a URL

CyrildeWit\MapsUrls\MapsUrl::for() takes an action and returns the URL.

Pass the parameters as named arguments and leave out the ones you do not need.

Campaign tracking

Google asks every URL to carry two tracking parameters. utm_source is the name of your application, and utm_campaign is the intent behind the link, such as directions_request.

Build a CyrildeWit\MapsUrls\UrlGenerator with the source and generate through it. The source is the same for every link you build, so it belongs on the generator.

The campaign describes one link, so generate() takes it per call. Pass utmCampaign to the constructor as well if most of your links share one, and the argument to generate() overrides it.

Both parameters are optional and independent. One you never set stays out of the query string. The package will not invent a source name on your behalf.

A generator holds nothing but these two strings and never changes, so one instance can serve your whole application.

Coordinates

Six parameters take a latitude/longitude pair. Four of them accept a place name instead: query, origin, destination and waypoints. The other two, center and viewpoint, are always a pair. Every one of them accepts a CyrildeWit\MapsUrls\Coordinates instance.

Coordinates writes the pair with at most seven decimals, the precision Google uses in its own examples, which resolves to about a centimetre. It drops trailing zeros, so new Coordinates(41, 2) becomes 41,2, and it rounds away anything below the seventh decimal.

[!WARNING] Format the pair through this class rather than interpolating the floats yourself. Casting a float to a string honours the precision ini setting, so a host running precision=6 writes 47.5951518 as 47.5952, a ten metre error in a URL that still looks right. The cast also switches to exponential notation below 1e-4, and Google does not read 1.0E-7 as a latitude.

A latitude outside -90 to 90 or a longitude outside -180 to 180 throws CyrildeWit\MapsUrls\Exceptions\InvalidOption. A longitude past the antimeridian wraps back around the globe and Google reads it, so Coordinates::unchecked() skips the check for anyone who has one and would rather not normalise it first.

Actions

The Google Maps URLs API allows you to generate a URL that performs a certain action. Each action has its own class.

Creating an action from an array

Every action class has a static fromArray(array $options) method for options that arrive at runtime, from configuration or from JSON. The keys are the query parameter names from the Google Maps URLs API, not the constructor argument names. When you know the options while writing the code, use named arguments instead and let the compiler check them.

The same rules apply to every action:

[!NOTE] A keyed coordinates array is rejected, because reading it in the wrong order swaps the latitude and the longitude and still produces a URL that loads.

Each action lists its own keys below.

Search

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.

Google Maps URLs documentation

CyrildeWit\MapsUrls\Actions\Search takes:

Argument Option Type
query query string or Coordinates
queryPlaceId query_place_id string or null

Google requires the query, so it has no default. A place ID narrows a query rather than replacing one, and fromArray() without a query key throws InvalidOption.

Creating from an array

See creating an action from an array for the shared rules.

Directions

Request directions and launch Google Maps with the results.

Google Maps URLs documentation

CyrildeWit\MapsUrls\Actions\Directions takes:

Argument Option Type
origin origin string, Coordinates or null
originPlaceId origin_place_id string or null
destination destination string, Coordinates or null
destinationPlaceId destination_place_id string or null
travelMode travelmode TravelMode or null
directionAction dir_action DirectionAction or null
waypoints waypoints list of string or Coordinates
waypointPlaceIds waypoint_place_ids list of string
avoid avoid list of Avoid
Travel mode

The cases of CyrildeWit\MapsUrls\Enums\TravelMode are:

Bicycling is human-powered. TwoWheeler covers motorised two-wheelers such as motorcycles, and Google only routes it in countries where two-wheeler directions are supported. Elsewhere the link still opens, but the mode is ignored.

Direction action

CyrildeWit\MapsUrls\Enums\DirectionAction has one case, DirectionAction::Navigate.

Place IDs

Google reads a place ID only next to the location it belongs to, so originPlaceId needs an origin and destinationPlaceId needs a destination. One on its own throws InvalidOption.

The origin and the destination are both optional. Leaving the origin out asks Google Maps to route from wherever the user is.

Waypoints and their place IDs

Google matches the two lists by position, so the first place ID belongs to the first waypoint. Leaving the place IDs out entirely is fine.

[!WARNING] Passing a different number of place IDs than waypoints throws InvalidOption. A short list shifts every waypoint after it onto the wrong ID, and the route that comes back still looks plausible.

Google supports up to nine waypoints, and up to three when the link opens in a mobile browser. The package does not enforce either, since which one applies depends on where the link is opened.

Avoid

The cases of CyrildeWit\MapsUrls\Enums\Avoid are:

Google treats these as a preference rather than a rule. A route that cannot avoid the feature is still returned.

Creating from an array

See creating an action from an array for the shared rules.

DisplayMap

Launch Google Maps with no markers or directions.

Google Maps URLs documentation

CyrildeWit\MapsUrls\Actions\DisplayMap takes:

Argument Option Type
center center Coordinates or null
zoom zoom int or null
baseMap basemap BaseMap or null
layer layer Layer or null

Google requires the map_action parameter. This action always writes map_action=map.

Zoom

Whole numbers from 0 (the whole world) to 21 (individual buildings). Anything outside that range throws InvalidOption. Google notes that the upper limit varies with the map data available at the location, so a zoom of 21 is not guaranteed everywhere.

Base map

The cases of CyrildeWit\MapsUrls\Enums\BaseMap are:

Layer

The cases of CyrildeWit\MapsUrls\Enums\Layer are:

[!NOTE] Layer::None writes layer=none, which asks Google for a map with no layer on top. Leaving the layer unset omits the parameter instead. The two are not the same request, though they usually render the same map.

Creating from an array

See creating an action from an array for the shared rules.

StreetViewPanorama

Launch an interactive panorama image.

Google Maps URLs documentation

CyrildeWit\MapsUrls\Actions\StreetViewPanorama takes:

Argument Option Type
viewpoint viewpoint Coordinates or null
panoramaId pano string or null
heading heading int or null
pitch pitch int or null
fov fov int or null

Google requires the map_action parameter. This action always writes map_action=pano.

Google needs somewhere to point the camera, so one of viewpoint and panoramaId has to be present. An action with neither throws InvalidOption. Giving both is fine: the panorama ID wins, and the viewpoint is used only when Google cannot find that panorama.

heading runs from -180 to 360 degrees, pitch from -90 to 90 and fov from 10 to 100. Anything outside those ranges throws InvalidOption.

Creating from an array

See creating an action from an array for the shared rules.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

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.


All versions of php-maps-urls with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cyrildewit/php-maps-urls contains the following files

Loading the files please wait ...