Markers identify locations on the map. By default, they use a standard icon.
First of all, if you want to render a marker, you will need to build one. So let's go:
use Ivory\GoogleMap\Base\Coordinate;
use Ivory\GoogleMap\Overlay\Marker;
$marker = new Marker(new Coordinate());
The marker constructor requires a coordinate as first argument which represents the marker position. It also accepts additional parameters such as the animation (default null), icon (default null), shape (default null) and options (default empty):
use Ivory\GoogleMap\Base\Coordinate;
use Ivory\GoogleMap\Overlay\Animation;
use Ivory\GoogleMap\Overlay\Icon;
use Ivory\GoogleMap\Overlay\Marker;
use Ivory\GoogleMap\Overlay\MarkerShape;
use Ivory\GoogleMap\Overlay\MarkerShapeType;
$marker = new Marker(
new Coordinate(),
Animation::BOUNCE,
new Icon(),
new MarkerShape(MarkerShapeType::CIRCLE, [1.1, 2.1, 1.4])
['clickable' => false]
);
A variable is automatically generated when creating a marker but if you want to update it, you can use:
$marker->setVariable('marker');
If you want to update the marker position, you can use:
use Ivory\GoogleMap\Base\Coordinate;
$marker->setPosition(new Coordinate(1, 1));
If you want to add animation on marker, you can use:
$marker->setAnimation(Animation::DROP);
If you want to update the marker icon, you can use:
use Ivory\GoogleMap\Overlay\Icon;
$marker->setIcon(new Icon());
If you want to learn more about icon, you can read its documentation.
If you want to update the marker shape, you can use:
use Ivory\GoogleMap\Overlay\MarkerShape;
use Ivory\GoogleMap\Overlay\MarkerShapeType;
$marker->setIcon(new MarkerShape(MarkerShapeType::CIRCLE, [1.1, 2.1, 1.4]));
The marker options allows you to configure additional marker aspects. See the list of available options in the official documentation. Then, to configure them, you can use:
$marker->setOption('flat', true);
If you want to learn more about marker shape, you can read its documentation.
$map->getOverlayManager()->addMarker($marker);