Skip to content

Examples

Matt Sparks edited this page Jul 4, 2017 · 5 revisions

For installation instructions, see the Installation page.

Basic Example

At a minimum, Static Maps requires the main StaticMaps class and the Map component.

use SparksCoding\StaticMaps\StaticMap;
use SparksCoding\StaticMaps\Components\Map;

// Add your api key
$staticMap = StaticMap::key('your_api_key');

// Set the builder
$staticMap->setBuilder('\SparksCoding\StaticMaps\Builders\GoogleStaticMapBuilder');

// Add the map
$staticMap->setMap(
    Map::create()->center('New York, NY')->zoom(10)
);

// Get the URI
$staticMap->uri();

Add Markers

$staticMap->addMarkers(
    Marker::location('Midtown Manhattan, New York, NY'),
    Marker::location('Brooklyn, NY'),
    Marker::location('Empire State Building'),
);

Add Styles

$staticMap->addStyles(
    Feature::name('road')->elements(
        Element::name('geometry')->color('blue')
    ),
    Feature::name('landscape')->elements(
        Element::name('labels')->color('red')
    )
);

Add Path

$staticMap->addPath(
  Path::points([
      'Empire State Building',
      'Webster Hall',
      'The Spotted Pig',
      'The High Line',
      'Empire State Building',
  ])->color('0x000000ff')->fillcolor('0xFFFF0033')->weight(2)
);
Clone this wiki locally