Vue Baidu Map is a component library providing Baidu Map integration for Vue.js 2.x applications. It allows developers to easily embed interactive Baidu Maps and leverage various features like markers, overlays, and controls within their Vue projects. The current stable version is 0.21.22. While it has seen recent updates (as of September 2023), its explicit focus on Vue 2.x places it in a maintenance state, especially given Vue 2's End of Life in December 2023. Key differentiators include its tight integration with Baidu's localized mapping services, which are critical for applications targeting users in mainland China, where other global map providers may have limited or no service.
npm install vue-baidu-mapVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the installation, initialization with an API key, and basic usage of the `<baidu-map>` component with a marker and zoom controls in a Vue 2 application. It highlights the essential setup and provides styling.
For Vue 3 projects, migrate to an actively maintained Vue 3 compatible Baidu Map library like `vue-baidu-map-3x` or `vue3-baidu-map-gl`.
Ensure you have obtained a valid 'Browser' API Key from the Baidu LBS Cloud platform (http://lbsyun.baidu.com/apiconsole/key) and provide it to the `ak` option during `Vue.use(BaiduMap, { ak: 'YOUR_KEY' })`.Add CSS rules for the map container class or ID, specifying `width` and `height` (e.g., `.map { width: 100%; height: 300px; }`).Evaluate your target audience. If international reach is critical and Baidu-specific features are not required, consider alternatives like Google Maps or OpenStreetMap-based solutions. If targeting China, ensure adherence to Baidu's specific development guidelines and local regulations.
Verify that your Baidu Map API key's settings on the Baidu LBS Cloud console match the environment where your application is running (e.g., ensure your domain is whitelisted for browser applications). Different key types might be needed for different use cases.
Obtain a valid Baidu Map API Key from the Baidu LBS Cloud platform (http://lbsyun.baidu.com/apiconsole/key) and pass it as the `ak` option during plugin registration.
Ensure `Vue` is imported (`import Vue from 'vue'`) and available in the scope where `BaiduMap` is initialized, especially in non-SFC setups. For CDN usage, ensure Vue's script tag is loaded before this library's script.
Apply explicit `width` and `height` styles to the map container element, for example: `<style>.map { width: 100%; height: 400px; }</style>`.Check your network connection, verify the `ak` provided is correct and valid, and ensure no Content Security Policy (CSP) rules are blocking `http://api.map.baidu.com/api` or `https://api.map.baidu.com/api`.