国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

vue使用Google地圖的實(shí)現(xiàn)示例代碼

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:02:24
文檔

vue使用Google地圖的實(shí)現(xiàn)示例代碼

vue使用Google地圖的實(shí)現(xiàn)示例代碼:最近用Vue開發(fā)后臺系統(tǒng)時(shí),有些數(shù)據(jù)需要在地圖上標(biāo)注出來,需要用到地圖功能,因?yàn)槭菄H項(xiàng)目,國內(nèi)的地圖不太適用,所以選用了Google地圖,谷歌地圖API: https://developers.google.cn/maps/documentation/javascript/tutorial
推薦度:
導(dǎo)讀vue使用Google地圖的實(shí)現(xiàn)示例代碼:最近用Vue開發(fā)后臺系統(tǒng)時(shí),有些數(shù)據(jù)需要在地圖上標(biāo)注出來,需要用到地圖功能,因?yàn)槭菄H項(xiàng)目,國內(nèi)的地圖不太適用,所以選用了Google地圖,谷歌地圖API: https://developers.google.cn/maps/documentation/javascript/tutorial

最近用Vue開發(fā)后臺系統(tǒng)時(shí),有些數(shù)據(jù)需要在地圖上標(biāo)注出來,需要用到地圖功能,因?yàn)槭菄H項(xiàng)目,國內(nèi)的地圖不太適用,所以選用了Google地圖,谷歌地圖API: https://developers.google.cn/maps/documentation/javascript/tutorial 。

一、必須的開發(fā)要求

1.獲取密鑰API Key

首先,要使用Google Maps JavaScript API,必須獲取一個(gè)可用的API密鑰,并且必須啟用結(jié)算,具體獲取步驟可百度查詢,在此就不一一敘述了,主要想講的地圖用法。

2.海外服務(wù)器IP

.想要使用谷歌地圖就需要翻墻了,公司購買的是發(fā)條云的賬號,在瀏覽器上下載發(fā)條云安裝,安裝好之后輸入用戶賬號和密碼進(jìn)行登錄,就可以選擇服務(wù)器進(jìn)行操作了。

海外模式的網(wǎng)速比較慢,一般開發(fā)谷歌地圖的時(shí)候,我才打開。

二、引入谷歌插件

使用npm進(jìn)行引入:

npm install vue-google-maps
//mian.js中:
import 'vue-googlemaps/dist/vue-googlemaps.css'
import VueGoogleMaps from 'vue-googlemaps'
Vue.use(VueGoogleMaps, {
 load: {
//填入申請的apiKey賬號
 apiKey: '',
 libraries: ['places'],
 useBetaRenderer: false,
 },
})

三、使用谷歌插件

1.使用方法

//創(chuàng)建dom
<div id="allmap" ref="allmap"></div>
 //創(chuàng)建谷歌地圖
 this.maps = new google.maps.Map(document.getElementById("allmap"), {
 //顯示一個(gè)滑動條來控制map的Zoom級別
 zoom: 13,
 //設(shè)置地圖中心點(diǎn)
 center: { lat: mapData[0].latitude, lng: mapData[0].longitude },
 //為了關(guān)閉默認(rèn)控件集,設(shè)置地圖的disableDefaultUI的屬性為true
 disableDefaultUI: true,
 // 通過單擊縮放控件來縮放地圖
 gestureHandling: 'cooperative', 
 // 刪除地圖上的“ 縮放”控件按鈕。
 zoomControl: false,
 // 控制地圖的類型 roadmap 地圖 terrain 地圖地形 
 satellite 衛(wèi)星圖像 hybrid 衛(wèi)星圖像+地名
 mapTypeId: 'satellite', 
 //語言可選值:en,zh_en, zh_cn
 language: zh_en 
 
 // 添加標(biāo)記 (紅色的標(biāo)點(diǎn))
 let marker = new google.maps.Marker({
 //標(biāo)點(diǎn)的位置
 position: { lat: 22.5397965915, lng: 114.0611121534 },
 map: this.maps,
 //標(biāo)點(diǎn)的名稱
 title: "中華人民共和國",
 //標(biāo)點(diǎn)中的文字
 label: "SZ",
 //標(biāo)點(diǎn)的動畫
 animation: google.maps.Animation.DROP
 });
 // 創(chuàng)建消息窗口DOM,將內(nèi)容包裝在HTML DIV中,以便設(shè)置InfoWindow的高度和寬度。
 let contentString =
 '<div class="content"><h3>地圖</h3><p>測試數(shù)據(jù)</p></div>';
 //地圖的消息窗口:InfoWindow
 let infowindow = new google.maps.InfoWindow({
 content: contentString
 });
 // 點(diǎn)擊標(biāo)點(diǎn)事件
 marker.addListener("click", function() {
 infowindow.open(this.maps, marker);
 });

示例圖片:

2.結(jié)合項(xiàng)目

//mapPAge.vue
<template>
 <div class="container">
 <div id="allmap" ref="allmap"></div>
 </div>
</template>
<script>
export default {
 mounted(){
 //在mounted中執(zhí)行地圖方法,mapData為要展示的數(shù)據(jù)
 this.initMap(mapData);
}
 methods:{
 initMap(mapData) {
 let that = this;
 // 創(chuàng)建google地圖
 this.maps = new google.maps.Map(document.getElementById("allmap"), {
 zoom: 13,
 //地圖中心點(diǎn),這里我以第一個(gè)數(shù)據(jù)的經(jīng)緯度來設(shè)置中心點(diǎn)
 center: { lat: mapData[0].latitude, lng: mapData[0].longitude },
 disableDefaultUI: false,
 zoomControl: false 
 }); 
 // 設(shè)置滿足條件的自定義標(biāo)記圖標(biāo)
 let imageblue = "@/img/map_blue.png";
 let imagered = "@/img/map_red.png";
 let imagegray = "@/img/map_gray.png";
 let infoWindow = new google.maps.InfoWindow();
 // 循環(huán)渲染數(shù)據(jù)
 mapData.map(currData=>{
 // 判斷當(dāng)前圖片
 let currImg = "";
 if (currData.line == 0) {
 currImg = imagegray;
 } else {
 if (currData.available >= 4) {
 currImg = imageblue;
 } else {
 currImg = imagered;
 }
 }
 let marker = new google.maps.Marker({
 position: { lat: currData.latitude, lng: currData.longitude },
 map: this.maps,
 title: currData.name,
 // 此處的icon為標(biāo)記的自定義圖標(biāo)
 icon: currImg,
 animation: google.maps.Animation.DROP
 });
 
 //多個(gè)標(biāo)記點(diǎn)的點(diǎn)擊事件
 (function(marker, currData) {
 google.maps.event.addListener(marker, "click", function(e) {
 let currLine =
 currData.line == 1? '在線': '離線';
 //設(shè)置消息窗口的統(tǒng)一內(nèi)容
 infoWindow.setContent(
 '<div class="content"><h3 style="margin-bottom:5px;font-size:20px;">' +
 currData.name +
 '</h3><p style="margin-bottom:5px;font-size:16px;">' +
 currData.address +
 '</p></h3><p style="display: flex;align-items:center;margin-bottom:5px;"><span style="display:inline-block;width:12px;height:12px;border-radius:50%;background:#4ECC77;"></span><span style="margin-left:5px;color:#4ECC77;">可用電池 ' +
 +currData.available +
 '<span style="display:inline-block;width:12px;height:12px;border-radius:50%;background:#FF485C;margin-left:25px;"></span><span style="margin-left:5px;color:#FF485C;">空倉 ' +
 +currData.empty +
 '</span></p><p style="color:#333;margin-top:5px;">機(jī)柜狀態(tài):<span style="color:#000;">' +currLine+
 '</span></p><p style="color:#333;margin-top:5px;">地理位置:<span style="color:#000;">lat:' +
 currData.latitude +
 ";log:" +
 currData.longitude +
 "</span></p></div>"
 );
 //調(diào)用 infoWindow.open
 infoWindow.open(this.maps, marker);
 });
 })(marker, currData);
 })
 }
 }
 }

示例圖片:

以上使用的是谷歌地圖的基本內(nèi)容,有興趣的小伙伴兒可以查看谷歌官方文檔,查看更多內(nèi)容,使用更多功能O(∩_∩)O。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

vue使用Google地圖的實(shí)現(xiàn)示例代碼

vue使用Google地圖的實(shí)現(xiàn)示例代碼:最近用Vue開發(fā)后臺系統(tǒng)時(shí),有些數(shù)據(jù)需要在地圖上標(biāo)注出來,需要用到地圖功能,因?yàn)槭菄H項(xiàng)目,國內(nèi)的地圖不太適用,所以選用了Google地圖,谷歌地圖API: https://developers.google.cn/maps/documentation/javascript/tutorial
推薦度:
標(biāo)簽: 使用 VUE 地圖
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 久久国产成人精品国产成人亚洲 | 欧美中文在线 | 国产亚洲免费观看 | 亚洲色图在线播放 | 碰91精品国产91久久婷婷 | 欧美精品日韩一区二区三区 | 一区二区三区观看 | 国产全部视频 | 久久99国产精品成人欧美 | 亚洲逼院 | 欧洲精品一区二区三区 | 在线国产一区二区 | 911国产视频 | 欧美精品久久久亚洲 | 久久精品亚洲欧美日韩久久 | 国产欧美日韩在线 | 中文 字幕 高清 在线 | 国产观看 | 欧美日韩无| 四虎国产精品免费久久久 | 青青操国产视频 | 欧洲欧美成人免费大片 | 欧美在线二区 | 国产成人3p视频免费观看 | 激情欧美一区二区三区 | 劲爆欧美精品13页 | 亚洲日韩在线观看 | 韩国理论三级在线观看视频 | 日韩电影免费看 | 亚洲色图第四页 | 久久福利资源网站免费看 | 日韩精品欧美亚洲高清有无 | 黄色国产在线视频 | 亚洲一区二区在线免费观看 | 日韩一级精品久久久久 | 日韩欧美一区二区三区免费看 | 国产最新在线视频 | 欧美综合在线观看 | 亚洲欧美中文日韩在线v日本 | 日韩视频免费看 | 四虎成人精品免费影院 |