zoomyboy / map by zoomyboy

Google Geocoding and DistanceMatrix Services for Laravel 5 Eloquent models
18
0
1
Package Data
Maintainer Username: zoomyboy
Maintainer Contact: philipp@aweos.de (Philipp Lang)
Package Create Date: 2017-09-01
Package Last Update: 2017-09-11
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:04:40
Package Statistics
Total Downloads: 18
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

map

This Package allows you to access Googles Geocoding and DistanceMatrix Service with an Eloquent model.

You should set the 'latitude' and 'longitude' and zip/city Attribute as a fillable:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Zoomyboy\Map\HasMap;

class M extends Model
{
	use HasMap;

  protected $fillable = ['latitude', 'longitude', 'address', 'zip', 'city'];
}

By default, the Attribute 'addressForCoords' is used to set the coords for the model. This is a string combination of the stored Address, Zip-Code and City. You can overwrite this behaviour by setting the 'getAddressForCoords' attribute.

You can leave of the 'address' attribute (set it to null or dont create a column at all), because the package will just fetch the position of the city and zip-Code.

Facade

The Map Facade can be used to manually grab the functions of the package:

use Zoomyboy\Map\Facades\Map;

Grab Coords
You can grab Cordinates with the 'coords' method. The Method acepts 3 Params: address, zip and city, where zip and city are optional.
You can also leave off the zip and city and put the full address string as the first param. Or you can set all 3 options - that way a proper google string is created out of this information. The method will return an array with the keys 'latitude' and 'longitude' - or false if the location wasn't found.

Map::coords('Address', 'Zip', 'City');

Grab Distances You can get the distance in Meters between 2 Locations.

Map::distance('Address 1, 12345 City 2', 'Address 2, 67890 City 2');