arcasolutions/google-map
Laravel package providing Google Maps integration for your app, with helpers to generate map views and include the required scripts. Useful for quickly embedding maps and configuring markers or map options within Laravel projects.
use Ivory\GoogleMap\Map;
use Ivory\GoogleMap\MapTypeId;
$map = new Map();
$map->setPrefixJavascriptVariable('map_');
$map->setHtmlContainerId('map_canvas');
$map->setAsync(false);
$map->setAutoZoom(false);
$map->setCenter(0, 0, true);
$map->setMapOption('zoom', 3);
$map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);
$map->setMapOption('mapTypeId', MapTypeId::ROADMAP);
$map->setMapOption('mapTypeId', 'roadmap');
$map->setMapOption('disableDefaultUI', true);
$map->setMapOption('disableDoubleClickZoom', true);
$map->setMapOptions(array(
'disableDefaultUI' => true,
'disableDoubleClickZoom' => true,
));
$map->setStylesheetOption('width', '300px');
$map->setStylesheetOption('height', '300px');
$map->setStylesheetOptions(array(
'width' => '300px',
'height' => '300px',
));
$map->setLanguage('en');
$map->setApiKey('ABQIAAAApsu_yVy ... PoWjn3yp6vDxlSg');
For configurating the map center & zoom, you have three possibilities:
To use the standard center coordinate & zoom, you need to disable the auto zoom flag & configure the center/zoom.
use Ivory\GoogleMap\Map;
$map = new Map();
// Disable the auto zoom flag
$map->setAutoZoom(false);
// Sets the center
$map->setCenter(0, 0, true);
// Sets the zoom
$map->setMapOption('zoom', 3);
For fitting a bound, you need to enable the auto zoom flag & configure bound south west & nort east coordinates. If you extend overlays with the bound, the map will fit the overlays coordinate instead of bound coordinates.
use Ivory\GoogleMap\Map;
$map = new Map();
// Enable the auto zoom flag
$map->setAutoZoom(true);
// Sets the bound coordinates
$map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);
For fitting a bound which extends overlays, you need to enable the auto zoom flag & add overlays to the bound. In the overlays documentation, you learn how you can add overlays to the map. If the auto zoom flag is enabled and you add some overlays to the map, the map bound will automatically extends your overlay. So, at the end, all your overlays will be visible on your sreen.
use Ivory\GoogleMap\Map,
Ivory\GoogleMap\Overlays\Marker;
$map = new Map();
// Enable the auto zoom flag
$map->setAutoZoom(true);
// Add marker overlay to your map
$map->addMarker(new Marker());
For configurating the map type, the better way is to follow the oriented object way. For that, the
Ivory\GoogleMap\MapTypeId is here. It allows you to access all constants which describe map types. If you don't
want to use this class, you can directly use the constant value.
use Ivory\GoogleMap\Map;
use Ivory\GoogleMap\MapTypeId;
$map = new Map();
// Sets your map type
$map->setMapOption('mapTypeId', MapTypeId::HYBRID);
$map->setMapOption('mapTypeId', 'hybrid');
$map->setMapOption('mapTypeId', MapTypeId::ROADMAP);
$map->setMapOption('mapTypeId', 'roadmap');
$map->setMapOption('mapTypeId', MapTypeId::SATELLITE);
$map->setMapOption('mapTypeId', 'satellite');
$map->setMapOption('mapTypeId', MapTypeId::TERRAIN);
$map->setMapOption('mapTypeId', 'terrain');
For loading the map asynchronously, you need to set the async property to true. Enabling this feature the map will load
asynchronously, allowing you to load the map through AJAX. To do this, the javascript code is wrapped by a function
called load_ivory_google_map and the script responsible to load Google API adds the callback parameter with
this value.
use Ivory\GoogleMap\Map;
$map = new Map();
$map->setAsync(true);
The helper renders an html javascript block with all code needed for displaying your map wrapped in the
load_ivory_google_map function.
<script type="text/javascript">
function load_ivory_google_map() {
// Code needed for displaying your map
}
</script>
Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map. Overlays reflect objects that you "add" to the map to designate points, lines, areas, or collections of objects.
The maps on Google Maps contain UI elements for allowing user interaction through the map. These elements are known as controls and you can include variations of these controls in your Google Maps API application. Alternatively, you can do nothing and let the Google Maps API handle all control behavior.
How can I help you explore Laravel packages today?