Skip to content

MacareuxDigital/md_google_map_attribute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Macareux Google Map Attribute

A Concrete CMS package to add a new attribute type to set location for objects with google map interface.

How to use

This package installs the "Google Map" attribute type.

You can set a location to objects like pages, users, express entries, etc. Please add an attribute key for objects. You have to get a Google Cloud Platform API Key that enables Places API and Maps Static API for it.

You can show Google Static MAP by Page Attribute Display block with no coding.

Get coordinates by code

/* @var \Concrete\Core\Page\Page $page */

// Display Static MAP
echo $page->getAttribute('your_attribute_handle');

/** @var \Macareux\Package\GoogleMapAttribute\Entity\GoogleMapValue $value */
$value = $page->getAttribute('your_attribute_handle');
if ($value) {
    // Get values manually
    $location = $value->getLocation();
    $latitude = $value->getLatitude();
    $longitude = $value->getLongitude();
    $zoom = $value->getZoom();
    $showMarker = $value->getMarker();
}

Sort ItemList the nearest item first

use Concrete\Core\Page\PageList;
use Macareux\Package\GoogleMapAttribute\Utility\QueryApplier;

$list = new PageList();
$currentLatitude = 35.6681625;
$currentLongitude = 139.6007834;
QueryApplier::applySortByNearest($list, 'your_attribute_handle', $currentLatitude, $currentLongitude);
$pages = $list->getResults();

If you don't familiar with PageList class, please check the official documentation: Searching and Sorting with the PageList object

Customize Static MAP

You can customize Static MAP by overriding Macareux\Package\GoogleMapAttribute\Utility\GoogleMapRenderer class.

use Macareux\Package\GoogleMapAttribute\Utility\GoogleMapRendererInterface;

$app->bind(GoogleMapRendererInterface::class, 'CustomRendererClassName');

License

MIT License.

Releases

No releases published

Packages

No packages published

Languages