A set of composable components for easy use of Google Maps in your Vue 3 projects.
A set of composable components for easy use of Google Maps in your Vue 3 projects.
Composable components for easy use of Google Maps with Vue 3
vue3-google-map offers a set of composable components for easy use of Google Maps in your Vue 3 projects.
Note: Please refer to the documentation site for rendered examples.
npm install vue3-google-map
# OR
pnpm add vue3-google-mapInclude the following script tag in your index.html (make sure to include it after Vue 3's global build).
All the map components are available on the Vue3GoogleMap global variable.
To construct a map using vue3-google-map you'll need to use the base GoogleMap component which receives your Google Maps API key, styles (e.g. setting width and height), and any MapOptions to configure your map (see this for all the supported MapOptions).
Other map features can be added to your map by passing map subcomponents (Marker, Polyline, Polygon, Rectangle, Circle, InfoWindow, CustomMarker, CustomControl, or MarkerCluster) to the default slot of the GoogleMap component.
The the following events will be emitted by the GoogleMap component and can be listened to by using @event_name.
This library is intended to be used in a composable fashion. Therefore you will find yourself using nested components to build your map rather than just a complicated inline format.
The main mapping component is GoogleMap, however the following components are available at your disposal:
3.64 or migrateUse the AdvancedMarker component to draw markers, drop pins or any custom icons on a map. AdvancedMarker is the new version offered by google when deprecated the Marker component (read more here).
In order to use the AdvancedMarker component it is necessary to specify a MapId on declaring the GoogleMap component (see more here).
[!IMPORTANT] If you're using the
AdvancedMarkercomponent with an external loader (using theapiPromiseprop), you must include themarkerlibrary:import { setOptions, importLibrary } from '@googlemaps/js-api-loader'; setOptions({ key: YOUR_GOOGLE_MAPS_API_KEY, v: 'weekly', }); const apiPromise = Promise.all([ importLibrary('maps'), importLibrary('marker'), // Required for AdvancedMarker component ]).then(() => window.google);
You can pass a AdvancedMarkerElementOptions object to the options prop to configure your marker.
You can also pass a PinElementOptions interface object to customize pin used by the marker.
Additionally, AdvancedMarker supports custom slot content via the content slot, allowing you to use custom HTML or Vue components inside the marker.
You can listen for the following events on the AdvancedMarker component.
[!WARNING] DEPRECATED: The
Markercomponent is deprecated as of February 2024. Please use theAdvancedMarkercomponent instead for new projects. The legacygoogle.maps.MarkerAPI will be removed in a future version. Learn more about the deprecation.
Use the Marker component to draw markers, drop pins or any custom icons on a map.
You can pass a MarkerOptions object to the options prop to configure your marker.
You can listen for the following events on the Marker component.
Use the Polyline component to draw paths and arbitrary shapes on a map.
You can pass a PolylineOptions object to the options prop to configure your polyline.
You can listen for the following events on the Polyline component.
Use the Polygon component to draw polgons (arbitrary number of sides) on a map.
You can pass a PolylgonOptions object to the options prop to configure your polyline.
You can listen for the following events on the Polygon component.
Use the Rectangle component to draw simple rectangles on a map.
You can pass a RectangleOptions object to the options prop to configure your rectangle.
You can listen for the following events on the Rectangle component.
Use the Circle component to draw circles on a map.
You can pass a CircleOptions object to the options prop to configure your circle.
You can listen for the following events on the Circle component.
Use the InfoWindow component to display content in a popup window above the map, at a given location.
You can pass an InfoWindowOptions object to the options prop to configure your info window. Note that you can optionally pass your content to the default slot of the InfoWindow component.
Content passed through slot
You can nest the InfoWindow component inside the Marker component to display an info window when the marker is clicked.
Uluru
You can nest the InfoWindow component inside the AdvancedMarker component to display an info window when the marker is clicked.
Sydney
Perth
You can use v-model to manage the state of the info window programmatically or to know whether it's open or closed
You can listen for the following events on the InfoWindow component.
Regular markers can be customized a great deal but if you need to you can use the CustomMarker component and provide your own custom markup through it's default slot.
| Parameter | Type | Description |
|---|---|---|
position |
{ lat: number, lng: number} |
Sets the marker position. |
anchorPoint |
'CENTER' | 'TOP_CENTER' |'BOTTOM_CENTER' | 'LEFT_CENTER' | 'RIGHT_CENTER' | 'TOP_LEFT' | 'TOP_RIGHT' | 'BOTTOM_LEFT' | 'BOTTOM_RIGHT' |
Sets how the marker is anchored relative to it's position point. Default is CENTER. |
offsetX |
number |
Horizontal offset from the position point. |
offsetY |
number |
Vertical offset from the position point. |
zIndex |
number |
z-index value of the marker. |
Use the CustomControl component to add custom buttons/controls to your map.
You can define the markup of your custom control in the default slot of the CustomControl component. The component itself takes two props:
position: Defines the position of your custom control on the map. Its value must be one of the ControlPosition constants.index (optional): Controls the order of placement for custom controls that occupy the same position.Refer to the Google Maps documentation on custom controls positioning.
Use the MarkerCluster component to display a large number of markers on a map. It will combine markers of close proximity into clusters, and simplify the display of markers on the map. Can be used with the Marker or CustomMarker components.
Simply pass your Marker/CustomMarker(s) in the default slot of the MarkerCluster component.
MarkerCluster accepts an options prop (an object) where you can configure algorithm, onClusterClick, and renderer from the MarkerClustererOptions interface. Note that all these options are completely optional but non-reactive.
You can listen for the following events on the MarkerCluster component.
MarkerCluster us
No open issues yet, or sync has not completed.