PHPackages                             mercynet/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. [Image &amp; Media](/categories/media)
4. /
5. mercynet/maps

ActiveLibrary[Image &amp; Media](/categories/media)

mercynet/maps
=============

A package to load maps with support for Leaflet and Google Maps

1.0.3(1y ago)04.9k↓30.8%MITPHPPHP ^8.3

Since Oct 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mercynet/maps)[ Packagist](https://packagist.org/packages/mercynet/maps)[ RSS](/packages/mercynet-maps/feed)WikiDiscussions main Synced 1mo ago

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

=======

Maps
====

[](#maps)

Maps is a PHP library designed to facilitate the integration and rendering of various map providers, such as Leaflet and Google Maps, in web applications. It adheres to SOLID principles, design patterns, and clean code practices, ensuring maintainability and scalability. The package allows developers to either use built-in views for map rendering or customize their own views by providing necessary data. It includes comprehensive tests using PestPHP to ensure reliability and correctness. The package is structured to be easily extendable, allowing the addition of more map providers in the future.

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

[](#installation)

1. Clone the repository:

```
   git clone https://github.com/mercynet/maps-project.git
   cd maps-project
```

2. Install dependencies using Composer:

```
   composer install
```

Configuration
-------------

[](#configuration)

Configure your map providers in `src/config/maps.php`:

```
return [
    'providers' => [
        'leaflet' => \Maps\Providers\Leaflet\LeafletMap::class,
        'google' => \Maps\Providers\GoogleMaps\GoogleMapsMap::class,
    ],
];
```

Usage
-----

[](#usage)

### Google Maps

[](#google-maps)

To use Google Maps, ensure you have a valid API key. Add the API key to the `GoogleMapConfig` class:

```
namespace Maps\Providers\GoogleMaps;

class GoogleMapConfig
{
    public static function defaultOptions(): array
    {
        return [
            'center' => [37.7749, -122.4194],
            'zoom' => 12,
            'mapType' => 'roadmap',
            'polygons' => [],
            'markers' => [],
            'overlays' => []
        ];
    }

    public static function getMapType(): string
    {
        return 'roadmap';
    }

    public static function getZoom(): int
    {
        return 12;
    }

    public static function getApiKey(): string
    {
        return 'YOUR_API_KEY';
    }
}
```

Example view file for Google Maps (`src/Providers/GoogleMaps/Views/map.php`):

```
>

    Google Map
