PHPackages                             cyrildewit/php-maps-urls - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cyrildewit/php-maps-urls

ActiveLibrary

cyrildewit/php-maps-urls
========================

Generate URLs for the Google Maps URLs API

v1.0.1(1y ago)69.4k↓33.3%1Apache-2.0PHPPHP ^7.4|^8.0CI passing

Since Jun 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cyrildewit/php-maps-urls)[ Packagist](https://packagist.org/packages/cyrildewit/php-maps-urls)[ Docs](https://github.com/cyrildewit/php-maps-urls)[ RSS](/packages/cyrildewit-php-maps-urls/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (7)Used By (0)

PHP Google Maps URLs
====================

[](#php-google-maps-urls)

[![Packagist](https://camo.githubusercontent.com/d79d2f2bd252e1d51b72b4523265d05dc9141b882c329f62a16e27c4adfff314/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637972696c64657769742f7068702d6d6170732d75726c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cyrildewit/php-maps-urls)[![run-tests](https://github.com/cyrildewit/php-maps-urls/workflows/run-tests/badge.svg)](https://github.com/cyrildewit/php-maps-urls/actions)[![StyleCI](https://camo.githubusercontent.com/bb96af10b163d10c144d425c6a3c2634fa97402927998bbb94bb6a0eef1559d8/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133333037393630372f736869656c643f7374796c653d666c61742d737175617265)](https://styleci.io/repos/133079607)[![Codecov branch](https://camo.githubusercontent.com/865dea5da44297bd203aeda71954cd7640ed4c5d4ea9d5eae343022b8bb2a70d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f637972696c64657769742f7068702d6d6170732d75726c732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/cyrildewit/php-maps-urls)[![Total Downloads](https://camo.githubusercontent.com/c5cf8af9e61161eeb7e8b882d7f14854fe6600289139d00de6f9685665995afa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f637972696c64657769742f7068702d6d6170732d75726c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cyrildewit/php-maps-urls)[![License](https://camo.githubusercontent.com/1768faa08d0a9a138be034b13a35233fb3378be2a32aaa62da6d72d0f5c8d80c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f637972696c64657769742f7068702d6d6170732d75726c732e7376673f7374796c653d666c61742d737175617265)](https://github.com/cyrildewit/php-maps-urls/blob/1.x/LICENSE)

This package allows you to build URLs for the [Google Maps URLs API](https://developers.google.com/maps/documentation/urls/guide).

Here's a quick example:

```
use CyrildeWit\MapsUrls\UrlGenerator;
use CyrildeWit\MapsUrls\Actions\SearchAction;
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$searchAction = (new SearchAction())
    ->setQuery('The Netherlands Amsterdam');
$searchUrl = (new UrlGenerator($searchAction))->generate();

$directionsAction = (new DirectionsAction())
    ->setOrigin('The Netherlands Amsterdam')
    ->setDestination('The Netherlands Utrecht');
$directionsUrl = (new UrlGenerator($directionsAction))->generate();
```

Overview
--------

[](#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](https://developers.google.com/maps/documentation/urls/guide).

Documentation
-------------

[](#documentation)

### Table of contents

[](#table-of-contents)

1. [Getting Started](#getting-started)
    - [Requirements](#requirements)
    - [Installation](#installation)
2. [Usage](#usage)
    - [Generating a URL](#generating-a-url)
    - [Actions](#actions)
        - [Search](#search)
        - [Directions](#directions)
        - [Displaying a map](#displaying-a-map)
        - [Display a Street View panorama](#display-a-street-view-panorama)
3. [Credits](#credits)
4. [License](#license)

Getting Started
---------------

[](#getting-started)

### Requirements

[](#requirements)

This package requires **PHP 7.4+**.

#### Version information

[](#version-information)

VersionStatusPHP Version^1.0Active support&gt;= 7.4.0### Installation

[](#installation)

You can install this package via Composer using:

```
composer require cyrildewit/php-maps-urls
```

Usage
-----

[](#usage)

### Generating a URL

[](#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`.

```
use CyrildeWit\MapsUrls\UrlGenerator;
use CyrildeWit\MapsUrls\Actions\SearchAction;

$searchAction = (new SearchAction())
    ->setQuery('Eindhoven, Nederland');
$searchUrl = (new UrlGenerator($searchAction))->generate();
```

Output `$searchUrl`: `https://www.google.com/maps/search/?api=1&query=Eindhoven,%20Nederland`

### Actions

[](#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

[](#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

[](#query)

To set the query of the search action, you can call the `setQuery(string $query)` method.

```
use CyrildeWit\MapsUrls\Actions\SearchAction;

$searchAction = (new SearchAction())
    ->setQuery('Eindhoven, Nederland');
```

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.

```
use CyrildeWit\MapsUrls\Actions\SearchAction;

$searchAction = (new SearchAction())
    ->setQueryCoordinates(47.5951518, -122.3316393);
```

###### Query Place ID

[](#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.

```
use CyrildeWit\MapsUrls\Actions\SearchAction;

$searchAction = (new SearchAction())
    ->setQueryPlaceId('ChIJn8N5VRvZxkcRmLlkgWTSmvM');
```

###### Magic make constructor

[](#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.

```
use CyrildeWit\MapsUrls\Actions\SearchAction;

$searchAction = SearchAction::make([
    'query' => 'Eindhoven, Nederland',
    'query_place_id' => 'ChIJn8N5VRvZxkcRmLlkgWTSmvM',
]);
```

#### Directions

[](#directions)

From the official documentation: "Request directions and launch Google Maps with the results."

###### Origin

[](#origin)

The origin can be defined using method `setOrigin(string $origin)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setOrigin('Eindhoven, Nederland');
```

###### Origin Place ID

[](#origin-place-id)

The origin place ID can be defined using method `setOriginPlaceId(string $placeId)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setOrigin('Eindhoven, Nederland')
    ->setOriginPlaceId('ChIJn8N5VRvZxkcRmLlkgWTSmvM');
```

###### Destination

[](#destination)

The destination can be defined using method `setDestination(string $destination)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setDestination('Monnickendam, Nederland');
```

###### Destination Place ID

[](#destination-place-id)

The destination place ID can be defined using method `setDestinationPlaceId(string $placeId)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setDestination('Monnickendam, Nederland')
    ->setDestinationPlaceId('ChIJTZfQeLgFxkcRQhAYGf9HbrU');
```

###### Travel Mode

[](#travel-mode)

The travel mode can be defined using method `setTravelMode(string $travelmode)`. The valid options are:

- `driving`
- `walking`
- `bicycling`
- `transit`

These options can be referenced using the constants defined in `CyrildeWit\MapsUrls\Enums\TravelMode`.

```
CyrildeWit\MapsUrls\Enums\TravelMode::DRIVING;
CyrildeWit\MapsUrls\Enums\TravelMode::WALKING;
CyrildeWit\MapsUrls\Enums\TravelMode::BICYCLING;
CyrildeWit\MapsUrls\Enums\TravelMode::TRANSIT;
```

Example:

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;
use CyrildeWit\MapsUrls\Enums\TravelMode;

$directionsAction = (new DirectionsAction())
    ->setTravelmode(TravelMode::BICYCLING);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidTravelMode` exception will be thrown when an invalid travel mode is provided.

###### Direction Action

[](#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.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;
use CyrildeWit\MapsUrls\Enums\DirectionAction;

$directionsAction = (new DirectionsAction())
    ->setDirectionAction(DirectionAction::NAVIGATE);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidDirectionAction` exception will be thrown when an invalid direction action is provided.

###### Waypoints

[](#waypoints)

The waypoints can be defined using method `setWaypoints(array $waypoints)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setWaypoints([
        'Berlin,Germany',
        'Paris,France'
    ]);
```

###### Waypoint place IDs

[](#waypoint-place-ids)

Waypoint place IDs can be defined using method `setWaypointPlaceIds(array $placeIds)`.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$directionsAction = (new DirectionsAction())
    ->setWaypoints([
        'Berlin,Germany',
        'Paris,France'
    ])
    ->setWaypointPlaceIds([
        'ChIJAVkDPzdOqEcRcDteW0YgIQQ',
        'ChIJD7fiBh9u5kcRYJSMaMOCCwQ'
    ]);
```

###### Magic make constructor

[](#magic-make-constructor-1)

To instantiate a directions action with initial query parameters values, you can make use of the magic `DirectionsAction::make(array $options)` method.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;
use CyrildeWit\MapsUrls\Enums\TravelMode;
use CyrildeWit\MapsUrls\Enums\DirectionAction;

$directionsAction = DirectionsAction::make([
    'origin' => 'Eindhoven, Nederland',
    'origin_place_id' => 'ChIJn8N5VRvZxkcRmLlkgWTSmvM',
    'destination' => 'Monnickendam, Nederland',
    'destination_place_id' => 'ChIJTZfQeLgFxkcRQhAYGf9HbrU',
    'travelmode' => TravelMode::DRIVING,
    'dir_action' => DirectionAction::NAVIGATE,
    'waypoints' => [
        'Berlin,Germany',
        'Paris,France'
    ],
    'waypoint_place_ids' => [
        'ChIJAVkDPzdOqEcRcDteW0YgIQQ',
        'ChIJD7fiBh9u5kcRYJSMaMOCCwQ'
    ],
]);
```

#### Displaying a map

[](#displaying-a-map)

From the official documentation: "Launch Google Maps with no markers or directions."

###### Map action

[](#map-action)

The `map_action` query parameter is required and is therefore added by default with value `map`.

###### Center

[](#center)

The center of the map can be defined by setting the coordinates using method `setCenter(float $latitude, float $longitude)`.

```
use CyrildeWit\MapsUrls\Actions\DisplayMapAction;

$displayMapAction = (new DisplayMapAction())
    ->setCenter(-33.8569, 151.2152);
```

###### Zoom

[](#zoom)

The zoom level of the map can be defined by using method `setZoom(int $zoom)`.

```
use CyrildeWit\MapsUrls\Actions\DisplayMapAction;

$displayMapAction = (new DisplayMapAction())
    ->setZoom(10);
```

###### Base Map

[](#base-map)

The base map can be defined using method `setBaseMap(string $baseMap)`. The valid options are:

- `none`
- `traffic`
- `bicycling`

These options can be referenced using the constants defined in `CyrildeWit\MapsUrls\Enums\TravelMode`.

```
CyrildeWit\MapsUrls\Enums\BaseMap::NONE;
CyrildeWit\MapsUrls\Enums\BaseMap::TRAFFIC;
CyrildeWit\MapsUrls\Enums\BaseMap::BICYCLING;
```

Example:

```
use CyrildeWit\MapsUrls\Actions\DisplayMapAction;
use CyrildeWit\MapsUrls\Enums\BaseMap;

$displayMapAction = (new DisplayMapAction())
    ->setBaseMap(BaseMap::TRAFFIC);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidBaseMap` exception will be thrown when an invalid base map is provided.

###### Layer

[](#layer)

The layer can be defined using method `setLayer(string $layer)`. The valid options are:

- `none`
- `transit`
- `traffic`
- `bicycling`

These options can be referenced using the constants defined in `CyrildeWit\MapsUrls\Enums\Layer`.

```
CyrildeWit\MapsUrls\Enums\Layer::NONE;
CyrildeWit\MapsUrls\Enums\Layer::TRANSIT;
CyrildeWit\MapsUrls\Enums\Layer::TRAFFIC;
CyrildeWit\MapsUrls\Enums\Layer::BICYCLING;
```

Example:

```
use CyrildeWit\MapsUrls\Actions\DisplayMapAction;
use CyrildeWit\MapsUrls\Enums\Layer;

$displayMapAction = (new DisplayMapAction())
    ->setLayer(Layer::TRAFFIC);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidLayer` exception will be thrown when an invalid layer is provided.

###### Magic make constructor

[](#magic-make-constructor-2)

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.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;
use CyrildeWit\MapsUrls\Enums\BaseMap;
use CyrildeWit\MapsUrls\Enums\Layer;

$displayMapAction = DirectionsAction::make([
     'center' => [-33.8569, 151.2152],
     'zoom' => 10,
     'basemap' => BaseMap::BICYCLING,
     'layer' => Layer::TRANSIT,
]);
```

#### Display a Street View panorama

[](#display-a-street-view-panorama)

From the official documentation: "Launch an interactive panorama image."

###### Map action

[](#map-action-1)

The `map_action` query parameter is required and is therefore added by default with value `pano`.

###### Viewpoint

[](#viewpoint)

The viewpoint can be defined using method `setViewpoint(float $latitude, float $longitude)`.

```
use CyrildeWit\MapsUrls\Actions\DisplayStreetViewPanoramaAction;

$displayStreetViewPanoramaAction = (new DisplayStreetViewPanoramaAction())
    ->setViewpoint(48.857832, 2.295226);
```

###### Panorama ID

[](#panorama-id)

The panorama ID can be defined using method `setPanoramaId(string $id)`.

```
use CyrildeWit\MapsUrls\Actions\DisplayStreetViewPanoramaAction;

$displayStreetViewPanoramaAction = (new DisplayStreetViewPanoramaAction())
    ->setPanoramaId('tu510ie_z4ptBZYo2BGEJg');
```

###### Heading

[](#heading)

The heading can be defined using method `setHeading(int $degrees)`. Only values from 180 to 360 degrees are expected.

```
use CyrildeWit\MapsUrls\Actions\DisplayStreetViewPanoramaAction;

$displayStreetViewPanoramaAction = (new DisplayStreetViewPanoramaAction())
    ->setHeading(120);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidHeading` exception will be thrown when an invalid heading is provided.

###### Pitch

[](#pitch)

The pitch can be defined using method `setPitch(int $degrees)`. Only values from -90 to 80 degrees are expected.

```
use CyrildeWit\MapsUrls\Actions\DisplayStreetViewPanoramaAction;

$displayStreetViewPanoramaAction = (new DisplayStreetViewPanoramaAction())
    ->setPitch(40);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidPitch` exception will be thrown when an invalid heading is provided.

###### Fov

[](#fov)

The pitch can be defined using method `setFov(int $degrees)`. Only values from -10 to 100 degrees are expected.

```
use CyrildeWit\MapsUrls\Actions\DisplayStreetViewPanoramaAction;

$displayStreetViewPanoramaAction = (new DisplayStreetViewPanoramaAction())
    ->setFov(80);
```

The `CyrildeWit\MapsUrls\Exceptions\InvalidFov` exception will be thrown when an invalid heading is provided.

###### Magic make constructor

[](#magic-make-constructor-3)

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.

```
use CyrildeWit\MapsUrls\Actions\DirectionsAction;

$displayStreetViewPanoramaAction = DirectionsAction::make([
    'viewpoint' => [48.857832, 2.295226],
    'pano' => 'tu510ie_z4ptBZYo2BGEJg',
    'heading' => 120,
    'pitch' => 40,
    'fov' => 80,
]);
```

Credits
-------

[](#credits)

- **Cyril de Wit** - *Creator* - [cyrildewit](https://github.com/cyrildewit)

See also the list of [contributors](https://github.com/cyrildewit/php-maps-url/graphs/contributors) who participated in this project.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance42

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~606 days

Total

5

Last Release

485d ago

Major Versions

0.x-dev → v1.0.02021-02-01

PHP version history (2 changes)v0.1.0PHP ^7.0

v1.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16477999?v=4)[Cyril de Wit](/maintainers/cyrildewit)[@cyrildewit](https://github.com/cyrildewit)

---

Top Contributors

[![cyrildewit](https://avatars.githubusercontent.com/u/16477999?v=4)](https://github.com/cyrildewit "cyrildewit (69 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

google-maps-apigoogle-maps-url-apiphpurl-generatorurlphpgooglemapsurls

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cyrildewit-php-maps-urls/health.svg)

```
[![Health](https://phpackages.com/badges/cyrildewit-php-maps-urls/health.svg)](https://phpackages.com/packages/cyrildewit-php-maps-urls)
```

###  Alternatives

[jeroendesloovere/geolocation-php-api

This Geolocation PHP class connects to Google Maps API to find latitude/longitude or address.

75316.8k4](/packages/jeroendesloovere-geolocation-php-api)[gdg-tangier/cloud-pubsub

Google Cloud pub-sub for laravel

5054.9k](/packages/gdg-tangier-cloud-pubsub)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
