百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vue3-google-map

> 前端框架
开源

一组可组合的组件,可在您的 Vue 3 项目中轻松使用 Google Maps。

378 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一组可组合的组件,可在您的 Vue 3 项目中轻松使用 Google Maps。

vue3-google-map

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.

Table of Contents

  • Getting Started
    • Installation
    • Your First Map
  • Components
    • Advanced Marker
    • Marker ⚠️ Deprecated
    • Polyline
    • Polygon
    • Rectangle
    • Circle
    • Info Window
    • Custom Marker
    • Custom Control
    • Marker Cluster
    • Heatmap Layer ⚠️ Removed
  • Advanced Usage
  • Contribution
  • License

Getting Started

Installation

NPM

bash
npm install vue3-google-map
# OR
pnpm add vue3-google-map

CDN

Include the following script tag in your index.html (make sure to include it after Vue 3's global build).

xml

All the map components are available on the Vue3GoogleMap global variable.

Codepen demo

Your First Map

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.

xml

  
    
  

Components

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:

  • AdvancedMarker
  • Marker ⚠️ Deprecated - Use AdvancedMarker instead
  • Polyline
  • Polygon
  • Rectangle
  • Circle
  • InfoWindow
  • CustomMarker
  • CustomControl
  • MarkerCluster
  • HeatmapLayer ⚠️ Removed — pin API to 3.64 or migrate

Advanced Marker

Use 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 AdvancedMarker component with an external loader (using the apiPromise prop), you must include the marker library:

javascript
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);

Options

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.

xml

  
    
    
      
        

      
    
  

Events

You can listen for the following events on the AdvancedMarker component.

Marker

[!WARNING] DEPRECATED: The Marker component is deprecated as of February 2024. Please use the AdvancedMarker component instead for new projects. The legacy google.maps.Marker API 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.

Options

You can pass a MarkerOptions object to the options prop to configure your marker.

xml

  
    
  

Events

You can listen for the following events on the Marker component.

Polyline

Use the Polyline component to draw paths and arbitrary shapes on a map.

Options

You can pass a PolylineOptions object to the options prop to configure your polyline.

xml

  
    
  

Events

You can listen for the following events on the Polyline component.

Polygon

Use the Polygon component to draw polgons (arbitrary number of sides) on a map.

Options

You can pass a PolylgonOptions object to the options prop to configure your polyline.

xml

  
    
  

Events

You can listen for the following events on the Polygon component.

Rectangle

Use the Rectangle component to draw simple rectangles on a map.

Options

You can pass a RectangleOptions object to the options prop to configure your rectangle.

xml

  
    
  

Events

You can listen for the following events on the Rectangle component.

Circle

Use the Circle component to draw circles on a map.

Options

You can pass a CircleOptions object to the options prop to configure your circle.

xml

  
    
  

Events

You can listen for the following events on the Circle component.

Info Window

Use the InfoWindow component to display content in a popup window above the map, at a given location.

Options

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.

xml

  
    
    
      Content passed through slot
    
  

Use with Marker

You can nest the InfoWindow component inside the Marker component to display an info window when the marker is clicked.

xml

  
    
      
        

          
Uluru

          

        
      
    
  

Use with AdvancedMarker

You can nest the InfoWindow component inside the AdvancedMarker component to display an info window when the marker is clicked.

xml

  
    
      
        
Sydney

        

      
    

    
      
        

      
      
        
Perth

        

      
    
  

Open and close the Info Window

You can use v-model to manage the state of the info window programmatically or to know whether it's open or closed

xml

  
    
      
        

      
    
  

Events

You can listen for the following events on the InfoWindow component.

Custom Marker

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.

Options

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.
xml

  
    
      

        
      
    
  

Custom Control

Use the CustomControl component to add custom buttons/controls to your map.

Usage

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.

xml

  
    
      
    
  

Marker Cluster

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.

Usage

Simply pass your Marker/CustomMarker(s) in the default slot of the MarkerCluster component.

xml

  
    
      
    
  

Options

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.

Events

You can listen for the following events on the MarkerCluster component.

Performance Optimization

MarkerCluster us

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptgoogle-mapstypescriptvuevue3

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架