欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 谷歌地图Google JS API 实现

谷歌地图Google JS API 实现

2024/10/24 1:48:34 来源:https://blog.csdn.net/sky8880/article/details/140217612  浏览:    关键词:谷歌地图Google JS API 实现

demo实现

实现源码👇

// 谷歌地图Google JS API 实现
<template><div class="myMap"><gmp-map :center="center" zoom="15" map-id="ab6b6643adfa1a70"><gmp-advanced-markerv-for="(res, index) in myLatlng":key="index":position="`${res.latitude},${res.longitude}`":title="res.name":content="res.address"gmp-click@touchend="clickFn($event, res)"><imgclass="flag-icon":src="require(`@/assets/images/helpSupport/agent/${center == `${res.latitude},${res.longitude}` ? 'point2' : 'point1'}.png`)"/></gmp-advanced-marker></gmp-map></div>
</template><script>
import loadScript from "@/utils/loadScript.js";
export default {props: {myLatlng: {type: Array,default: () => [],},currentIndex: {type: Number,default: 0,},center: {type: String,required: true,},},watch: {myLatlng: {handler(newDate) {if (newDate.length > 0) {// window.initMap();}},},currentIndex: {handler(index) {this.center = `${this.myLatlng[index].latitude},${this.myLatlng[index].longitude}`;console.log(index, this.myLatlng[index]);},},},computed: {getLocation() {return window.navigator.geolocation;},},data() {return {infoWindow: null,};},mounted() {},async created() {let key = "AIzaSyBNCb603utwcJKOno8q69DUh2iuyCNmz4U";await loadScript(`https://maps.googleapis.com/maps/api/js?&key=${key}&loading=async&libraries=marker&v=beta&solution_channel=GMP_CCS_complexmarkers_v3`);},methods: {clickFn(e, res) {console.log(e, e.target.offsetParent);const contentString = ` <div class='maptotip' style=" display: flex;flex-direction:             column;align-items: flex-start;justify-content: center;color:#333333;font-weight: 400;text-align: left;"><p style=" font-family: OPPOSans;font-size: 20px;color: #21A56C;">${res.name}</p><p style=" font-family: OPPOSans;font-size: 18px;">${res.address}</p><p style=" font-family: OPPOSans;font-size: 18px;color: #666666;">电话:${res.contractPhone}</p></div > `;this.infoWindow = new google.maps.InfoWindow({content: contentString,ariaLabel: res.name,});this.infoWindow.open({ anchor: e.target.offsetParent });},},
};
</script>
<style lang="less">
.myMap {width: 100%;height: 100%;overflow: hidden;
}.flag-icon {width: 35px;height: 45px;
}.maptotip {width: 200px;height: auto;display: flex;flex-direction: column;align-items: flex-start;justify-content: center;gap: 5px;background-color: rgba(243, 249, 254, 0.9);> p {&:nth-child(1) {font-family: OPPOSans;font-size: 32px;font-weight: 400;line-height: 42.21px;text-align: left;color: #333333;}&:nth-child(2) {font-family: OPPOSans;font-size: 26px;font-weight: 400;line-height: 34.29px;text-align: left;color: #333333;}&:nth-child(3) {font-family: OPPOSans;font-size: 24px;font-weight: 400;line-height: 31.66px;text-align: left;color: #666666;}}
}
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com