PHPackages                             jamesil/nova-google-polygon - 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. jamesil/nova-google-polygon

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

jamesil/nova-google-polygon
===========================

A Laravel Nova Google polygon field.

V2.0.1(2mo ago)0387↑173.3%[3 issues](https://github.com/jamesil/nova-google-polygon/issues)[3 PRs](https://github.com/jamesil/nova-google-polygon/pulls)MITPHPPHP ^8.2CI passing

Since Aug 11Pushed 1mo agoCompare

[ Source](https://github.com/jamesil/nova-google-polygon)[ Packagist](https://packagist.org/packages/jamesil/nova-google-polygon)[ Docs](https://github.com/jamesil/nova-google-polygon)[ RSS](/packages/jamesil-nova-google-polygon/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (17)Versions (22)Used By (0)

Nova Google Polygon Field
=========================

[](#nova-google-polygon-field)

[![Tests](https://github.com/jamesil/nova-google-polygon/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/jamesil/nova-google-polygon/actions/workflows/tests.yml)[![Check & fix styling](https://github.com/jamesil/nova-google-polygon/actions/workflows/styling.yml/badge.svg?branch=main)](https://github.com/jamesil/nova-google-polygon/actions/workflows/styling.yml)[![Latest Stable Version](https://camo.githubusercontent.com/26951320b494dbccbcb1adc7bf08a0f60f41bb7472c45fb5ad462cb8d8869cd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616d6573696c2f6e6f76612d676f6f676c652d706f6c79676f6e3f6c6162656c3d5061636b6167697374)](https://packagist.org/packages/jamesil/nova-google-polygon)[![Total Downloads](https://camo.githubusercontent.com/8d9a314b14b3ac0e656a81054bbe48b04420d720e436148325e9f0d895756288/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a616d6573696c2f6e6f76612d676f6f676c652d706f6c79676f6e)](https://packagist.org/packages/jamesil/nova-google-polygon)

A Laravel Nova field for creating and editing polygons on Google Maps.

Features
--------

[](#features)

- Interactive polygon drawing and editing on Google Maps
- Support for multiple polygon points
- Real-time coordinate updates
- Customizable map center and zoom
- Laravel model casting support
- Polygon containment checking utilities

Requirements
------------

[](#requirements)

- PHP 8.2 or higher for the 2.x line
- Laravel Nova 5.0+
- Laravel 12.0 or higher
- Google Maps API key with Maps JavaScript API enabled

Laravel 13 requires PHP 8.3+ plus Laravel Nova 5.8.0 or newer.

Version Compatibility
---------------------

[](#version-compatibility)

Package VersionLaravelLaravel NovaPHP1.x9.x - 11.x4.x or 5.x8.1+2.x12.x5.0+8.2+2.x13.x5.8+8.3+The `main` branch tracks the 2.x release line. The `1.x` line remains the maintenance line for Laravel 9 through 11 users.

Laravel 13 support was added by Nova in version 5.8.0, so do not use earlier Nova 5 releases on Laravel 13.

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

[](#installation)

Install the package via Composer:

```
composer require jamesil/nova-google-polygon:^2.0
```

If you need the legacy compatibility line instead:

```
composer require jamesil/nova-google-polygon:^1.0
```

Use `^1.0` for Laravel 9 to 11 projects. Use `^2.0` for Laravel 12 and 13 projects.

### Configuration

[](#configuration)

The package merges its default configuration automatically. You only need to publish the config file if you want to customize the defaults.

1. **Publish the configuration file** (optional):

```
php artisan vendor:publish --provider="Jamesil\NovaGooglePolygon\FieldServiceProvider"
```

2. **Set up your Google Maps API key**:

First, create a Google Cloud project and enable the Maps JavaScript API:

- Visit [Google Cloud Console](https://console.cloud.google.com)
- Create a new project or select an existing one
- Enable the Maps JavaScript API
- Create credentials to get your API key

3. **Add environment variables**:

Add these variables to your `.env` file:

```
NOVA_GOOGLE_POLYGON_API_KEY=your-google-maps-api-key
NOVA_GOOGLE_POLYGON_CENTER_LAT=48.858361
NOVA_GOOGLE_POLYGON_CENTER_LNG=2.336164
```

Usage
-----

[](#usage)

### Basic Field Usage

[](#basic-field-usage)

Add the field to your Nova resource:

```
use Jamesil\NovaGooglePolygon\GooglePolygon;

class Location extends Resource
{
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make('Name'),

            GooglePolygon::make('Coverage Area', 'coverage_area'),
        ];
    }
}
```

### Database Setup

[](#database-setup)

The polygon data is stored as JSON. Create a JSON column in your migration:

```
Schema::create('locations', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->json('coverage_area')->nullable();
    $table->timestamps();
});
```

### Model Casting

[](#model-casting)

Use the provided cast to automatically handle polygon data:

```
use Jamesil\NovaGooglePolygon\Casts\AsPolygon;

class Location extends Model
{
    protected $casts = [
        'coverage_area' => AsPolygon::class,
    ];
}
```

### Working with Polygons

[](#working-with-polygons)

The package provides utility classes for working with polygon data:

```
use Jamesil\NovaGooglePolygon\Support\Polygon;
use Jamesil\NovaGooglePolygon\Support\Point;

// Create a polygon
$polygon = new Polygon([
    ['lat' => 48.858361, 'lng' => 2.336164],
    ['lat' => 48.859361, 'lng' => 2.337164],
    ['lat' => 48.857361, 'lng' => 2.338164],
]);

// Check if a point is inside the polygon
$point = new Point(48.858500, 2.337000);
$isInside = $polygon->contain($point); // returns true

// Get bounding box
$boundingBox = $polygon->getBoundingBox();

// Get min/max coordinates
$minLat = $polygon->getMinLatitude();
$maxLat = $polygon->getMaxLatitude();
$minLng = $polygon->getMinLongitude();
$maxLng = $polygon->getMaxLongitude();
```

### Advanced Example

[](#advanced-example)

Here's a complete example of using the field with a taxi pickup zone system:

```
// Nova Resource
use Jamesil\NovaGooglePolygon\GooglePolygon;

class PickupZone extends Resource
{
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Zone Name'),
            Number::make('Base Fare'),
            Boolean::make('Active'),
            GooglePolygon::make('Pickup Area', 'pickup_area'),
        ];
    }
}

// Model
use Jamesil\NovaGooglePolygon\Casts\AsPolygon;
use Jamesil\NovaGooglePolygon\Support\Point;

class PickupZone extends Model
{
    protected $casts = [
        'pickup_area' => AsPolygon::class,
        'active' => 'boolean',
    ];

    public function isPickupAllowed($latitude, $longitude)
    {
        if (!$this->active || !$this->pickup_area) {
            return false;
        }

        $point = new Point($latitude, $longitude);
        return $this->pickup_area->contain($point);
    }

    public static function findAvailableZone($latitude, $longitude)
    {
        return static::where('active', true)
            ->get()
            ->first(function ($zone) use ($latitude, $longitude) {
                return $zone->isPickupAllowed($latitude, $longitude);
            });
    }

    public function getTotalFare($distance, $duration)
    {
        // Calculate fare based on zone's base fare
        return $this->base_fare + ($distance * 2.5) + ($duration * 0.5);
    }
}
```

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

[](#api-reference)

### Polygon Class Methods

[](#polygon-class-methods)

- `contain(Point|array $point)`: Check if a point is inside the polygon
- `pointOnVertex(Point|array $point)`: Check if a point is on a polygon vertex
- `getBoundingBox()`: Get the bounding box coordinates
- `getMinLatitude()`, `getMaxLatitude()`: Get latitude bounds
- `getMinLongitude()`, `getMaxLongitude()`: Get longitude bounds
- `getPoints()`: Get all polygon points
- `setPoints(array $points)`: Set polygon points

### Point Class Methods

[](#point-class-methods)

- `fromArray(array $input)`: Create a point from array
- `toArray()`: Convert point to array
- `toJson()`: Convert point to JSON

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Credits
-------

[](#credits)

- [James Embling](https://github.com/jamesil)
- Based on the original work by [YieldStudio](https://github.com/YieldStudio/nova-google-polygon)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance90

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% 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 ~61 days

Total

5

Last Release

79d ago

Major Versions

V1.1.0 → V2.0.02026-04-15

PHP version history (2 changes)1.x-devPHP ^8.1

V2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/12300c4c70c36ea468cb86f1d81504b00b3bda35e5cc43b1a4d8219b334a7285?d=identicon)[jamesil](/maintainers/jamesil)

---

Top Contributors

[![jamesil](https://avatars.githubusercontent.com/u/7086382?v=4)](https://github.com/jamesil "jamesil (16 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")

---

Tags

laravelgooglePolygonnovaareajamesil

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jamesil-nova-google-polygon/health.svg)

```
[![Health](https://phpackages.com/badges/jamesil-nova-google-polygon/health.svg)](https://phpackages.com/packages/jamesil-nova-google-polygon)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[mostafaznv/nova-map-field

Map Field for Laravel Nova

46107.9k](/packages/mostafaznv-nova-map-field)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[advoor/nova-editor-js

A Laravel Nova field bringing EditorJs magic to Nova.

92219.3k3](/packages/advoor-nova-editor-js)[datomatic/nova-enum-field

A Laravel Nova PHP 8.1 enum field with filters

20156.0k](/packages/datomatic-nova-enum-field)

PHPackages © 2026

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