PHPackages                             genealabs/laravel-maps - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. genealabs/laravel-maps

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

genealabs/laravel-maps
======================

Easy-peasy map integration for Laravel.

0.9.0(2y ago)8431.0k↓59.5%29MITPHPCI passing

Since Oct 14Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/mikebronner/laravel-maps)[ Packagist](https://packagist.org/packages/genealabs/laravel-maps)[ RSS](/packages/genealabs-laravel-maps/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (9)Versions (27)Used By (0)

laravel-maps
============

[](#laravel-maps)

[![GitHub (pre-)release](https://camo.githubusercontent.com/3050dea505e87b01a5241e2416cec0e8f35015d7bdcceaee77ceefe01e590577/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f47656e65614c6162732f6c61726176656c2d6d6170732f616c6c2e737667)](https://github.com/GeneaLabs/laravel-maps)[![Packagist](https://camo.githubusercontent.com/eec6d0f194b58c27be667c7e50b35756e6a2ee98057b2d6fa5411e256f218aa3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f47656e65614c6162732f6c61726176656c2d6d6170732e737667)](https://packagist.org/packages/genealabs/laravel-maps)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/GeneaLabs/laravel-maps/master/LICENSE)

Version Support
---------------

[](#version-support)

LaravelPHP11.x8.2, 8.3, 8.4, 8.512.x8.2, 8.3, 8.4, 8.513.x8.3, 8.4, 8.5Prerequisites
-------------

[](#prerequisites)

- PHP &gt;= 8.2
- Laravel &gt;= 11.0
- A [Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key)

Installation
------------

[](#installation)

```
composer require genealabs/laravel-maps
```

Add your Google Maps API key to `.env`:

```
GOOGLE_MAPS_API_KEY=your-api-key-here

```

Add the following entry to your `config/services.php` file:

```
'google' => [
    'maps' => [
        'api-key' => env('GOOGLE_MAPS_API_KEY'),
    ],
],
```

Usage
-----

[](#usage)

The package provides a `Map` facade and an `app('map')` helper. Both give you the same API — use whichever you prefer.

Every map follows the same pattern:

1. **Initialize** the map with a config array.
2. **Add overlays** (markers, polylines, polygons, etc.).
3. **Create** the map to get the HTML and JavaScript output.
4. **Render** the output in your Blade view.

### Basic Map with Geolocation

[](#basic-map-with-geolocation)

This prompts the user for their location and centers the map on it:

```
use GeneaLabs\LaravelMaps\Facades\Map;

Route::get('/map', function () {
    Map::initialize([
        'center' => 'auto',
        'onboundschanged' => 'if (!centreGot) {
            var mapCentre = map.getCenter();
            marker_0.setOptions({
                position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng())
            });
        }
        centreGot = true;',
    ]);

    Map::add_marker([]);

    return view('map', ['map' => Map::create_map()]);
});
```

### Single Marker

[](#single-marker)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'draggableCursor' => 'default',
]);

Map::add_marker([
    'position' => '37.4419, -122.1419',
]);

$map = Map::create_map();
```

### Multiple Markers

[](#multiple-markers)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 'auto',
    'draggableCursor' => 'default',
]);

Map::add_marker([
    'position' => '37.429, -122.1519',
    'infowindow_content' => 'Hello World!',
    'icon' => 'https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000',
]);

Map::add_marker([
    'position' => '37.409, -122.1319',
    'draggable' => true,
    'animation' => 'DROP',
]);

Map::add_marker([
    'position' => '37.449, -122.1419',
    'onclick' => 'alert("You clicked the marker!")',
]);

$map = Map::create_map();
```

### Polyline

[](#polyline)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 'auto',
]);

Map::add_polyline([
    'points' => [
        '37.429, -122.1319',
        '37.429, -122.1419',
        '37.4419, -122.1219',
    ],
]);

$map = Map::create_map();
```

### Polygon

[](#polygon)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 'auto',
]);

Map::add_polygon([
    'points' => [
        '37.425, -122.1321',
        '37.4422, -122.1622',
        '37.4412, -122.1322',
        '37.425, -122.1021',
    ],
    'strokeColor' => '#000099',
    'fillColor' => '#000099',
]);

$map = Map::create_map();
```

### Drawing Tools

[](#drawing-tools)

```
Map::initialize([
    'drawing' => true,
    'drawingDefaultMode' => 'circle',
    'drawingModes' => ['circle', 'rectangle', 'polygon'],
]);

$map = Map::create_map();
```

### Directions

[](#directions)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 'auto',
    'directions' => true,
    'directionsStart' => 'Empire State Building',
    'directionsEnd' => 'Statue of Liberty',
    'directionsDivID' => 'directionsDiv',
]);

$map = Map::create_map();
```

When rendering, include a `` in your view to display the turn-by-turn directions.

### Street View

[](#street-view)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'map_type' => 'STREET',
    'streetViewPovHeading' => 90,
]);

$map = Map::create_map();
```

### Marker Clustering

[](#marker-clustering)

```
Map::initialize([
    'center' => '37.409, -122.1319',
    'zoom' => '13',
    'cluster' => true,
    'clusterStyles' => [
        [
            'url' => 'https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m1.png',
            'width' => '53',
            'height' => '53',
        ],
    ],
]);

Map::add_marker(['position' => '37.409, -122.1319']);
Map::add_marker(['position' => '37.409, -122.1419']);
Map::add_marker(['position' => '37.409, -122.1219']);
Map::add_marker(['position' => '37.409, -122.1519']);

$map = Map::create_map();
```

### KML Layer

[](#kml-layer)

```
Map::initialize([
    'zoom' => 'auto',
    'kmlLayerURL' => 'https://www.google.com/maps/d/kml?mid=your-kml-id',
]);

$map = Map::create_map();
```

### Circles

[](#circles)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 14,
]);

Map::add_circle([
    'center' => '37.4419, -122.1419',
    'radius' => 500,
    'strokeColor' => '#FF0000',
    'fillColor' => '#FF0000',
    'fillOpacity' => 0.35,
]);

$map = Map::create_map();
```

### Rectangles

[](#rectangles)

```
Map::initialize([
    'center' => '37.4419, -122.1419',
    'zoom' => 14,
]);

Map::add_rectangle([
    'bounds' => [
        '37.435, -122.155',
        '37.449, -122.129',
    ],
    'strokeColor' => '#FF0000',
    'fillColor' => '#FF0000',
    'fillOpacity' => 0.35,
]);

$map = Map::create_map();
```

### Ground Overlay

[](#ground-overlay)

```
Map::initialize([
    'center' => '40.7128, -74.0060',
    'zoom' => 13,
]);

Map::add_ground_overlay([
    'url' => 'https://example.com/overlay-image.png',
    'bounds' => [
        '40.700, -74.020',
        '40.730, -73.990',
    ],
    'opacity' => 0.5,
]);

$map = Map::create_map();
```

Rendering in Blade
------------------

[](#rendering-in-blade)

Pass the map data to your view and render the JavaScript in your `` and the HTML in your ``:

```

    {!! $map['js'] !!}

    {!! $map['html'] !!}

```

With a layout:

```
@section('scripts')
    {!! $map['js'] !!}
@endsection

@section('content')
    {!! $map['html'] !!}

@endsection
```

Controller Example
------------------

[](#controller-example)

For more complex setups, use a dedicated controller:

```
namespace App\Http\Controllers;

use GeneaLabs\LaravelMaps\Facades\Map;

class MapController extends Controller
{
    public function markers(): \Illuminate\View\View
    {
        Map::initialize([
            'center' => '37.4419, -122.1419',
            'zoom' => 'auto',
        ]);

        Map::add_marker([
            'position' => '37.429, -122.1519',
            'infowindow_content' => 'Location A',
        ]);

        Map::add_marker([
            'position' => '37.449, -122.1419',
            'infowindow_content' => 'Location B',
        ]);

        return view('maps.show', ['map' => Map::create_map()]);
    }

    public function directions(): \Illuminate\View\View
    {
        Map::initialize([
            'center' => '37.4419, -122.1419',
            'zoom' => 'auto',
            'directions' => true,
            'directionsStart' => 'San Francisco, CA',
            'directionsEnd' => 'San Jose, CA',
            'directionsDivID' => 'directionsDiv',
        ]);

        return view('maps.directions', ['map' => Map::create_map()]);
    }
}
```

API Reference
-------------

[](#api-reference)

The `Map` facade (or `app('map')`) exposes the following methods:

MethodDescription`initialize(array $config)`Configure map center, zoom, type, and behavior`add_marker(array $params)`Add a marker with position, info window, icon, etc.`add_polyline(array $params)`Draw a polyline from an array of points`add_polygon(array $params)`Draw a filled polygon from an array of points`add_circle(array $params)`Draw a circle with center and radius`add_rectangle(array $params)`Draw a rectangle from bounds`add_ground_overlay(array $params)`Overlay an image on the map`create_map()`Generate the map and return `['js' => ..., 'html' => ...]``get_lat_long_from_address(string $address)`Geocode an address to lat/lng### MultiPolygon from GeoJSON

[](#multipolygon-from-geojson)

To render a [GeoJSON MultiPolygon](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.7), decode the JSON and call `add_polygon()` once per polygon in the collection:

```
Route::get('/multipolygon', function () {
    $geojson = json_decode($geojsonString); // your GeoJSON MultiPolygon

    $config = ['center' => '-6.2, 106.8', 'zoom' => 10];
    app('map')->initialize($config);

    foreach ($geojson->coordinates as $polygon) {
        $points = [];

        // Each polygon may have an outer ring and optional holes — use the outer ring (index 0)
        foreach ($polygon[0] as $coord) {
            $points[] = $coord[1] . ', ' . $coord[0]; // GeoJSON is [lng, lat]; the library expects "lat, lng"
        }

        app('map')->add_polygon(['points' => $points]);
    }

    $map = app('map')->create_map();

    return '' . $map['js'] . '' . $map['html'] . '';
});
```

> **Note:** GeoJSON coordinates use `[longitude, latitude]` order, but this library expects `"latitude, longitude"` strings. The example above swaps them accordingly.

### Custom Overlay Popup

[](#custom-overlay-popup)

You can create a custom overlay popup that appears automatically (without requiring a click or hover) by using the `onload` configuration option together with the Google Maps JavaScript API [custom popup example](https://developers.google.com/maps/documentation/javascript/examples/overlay-popup).

The approach has two parts:

1. Define a custom `Popup` overlay class in a separate `` tag.
2. Use the `onload` option to instantiate the popup once the map finishes loading.

```
Route::get('/popup', function () {
    $lat = 37.4419;
    $lng = -122.1419;

    $config = [
        'center' => "{$lat}, {$lng}",
        'zoom' => 13,
        'onload' => "
            var position = new google.maps.LatLng({$lat}, {$lng});
            var popup = new Popup(position, document.getElementById('popup-content'));
            popup.setMap(map);
        ",
    ];

    app('map')->initialize($config);

    $map = app('map')->create_map();

    $popupScript =  '37.4419, -122.1419',
    'infowindow_content' => 'Hello!This popup opens on click.',
];
app('map')->add_marker($marker);
```

To auto-open a standard info window without a click, use the `onload` option:

```
$config = [
    'center' => '37.4419, -122.1419',
    'zoom' => 13,
    'onload' => 'google.maps.event.trigger(marker_0, "click");',
];
```

### More Examples

[](#more-examples)

BIOINSTALL has a great website showing how to do all the things with the class. No reason to reinvent the wheel, so [here](http://biostall.com/demos/google-maps-v3-api-codeigniter-library/) it is. The only thing to note is that `$this->googlemaps` is now either the facade `Map::` or the app variable `app('map')`.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance61

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 88.3% 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 ~156 days

Recently: every ~355 days

Total

15

Last Release

1033d ago

PHP version history (2 changes)0.5.0PHP &gt;=7.0.0

0.5.8PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/4374bfc5d8583aa8c25c5080f1fcfaf09027822f47724ba6b64abc564945c80a?d=identicon)[mikebronner](/maintainers/mikebronner)

---

Top Contributors

[![mikebronner](https://avatars.githubusercontent.com/u/1791050?v=4)](https://github.com/mikebronner "mikebronner (68 commits)")[![dansleboby](https://avatars.githubusercontent.com/u/4716382?v=4)](https://github.com/dansleboby "dansleboby (4 commits)")[![CristianEstiber](https://avatars.githubusercontent.com/u/52041211?v=4)](https://github.com/CristianEstiber "CristianEstiber (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![lukasmu](https://avatars.githubusercontent.com/u/28652053?v=4)](https://github.com/lukasmu "lukasmu (1 commits)")

---

Tags

laravelgooglemapsphpgmapsbiostall

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/genealabs-laravel-maps/health.svg)

```
[![Health](https://phpackages.com/badges/genealabs-laravel-maps/health.svg)](https://phpackages.com/packages/genealabs-laravel-maps)
```

###  Alternatives

[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90157.6k](/packages/emargareten-inertia-modal)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.8k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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