首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带有@ GoogleMaps /js的Vue.js googlemaps API -加载程序

带有@ GoogleMaps /js的Vue.js googlemaps API -加载程序
EN

Stack Overflow用户
提问于 2022-02-19 00:27:19
回答 3查看 893关注 0票数 3

谢谢你阅读我的问题:)

我试图在我的GoogleMaps项目中实现Vue.js,并使用@googlemaps/js加载器(来自https://developers.google.com/maps/documentation/javascript/overview#javascript)

我的守则如下:

代码语言:javascript
运行
复制
<script setup>
import { onMounted, ref } from 'vue'
import { Loader } from '@googlemaps/js-api-loader'

const loader = new Loader({
  apiKey: '',
  version: 'weekly',
  libraries: ['places']
})

const map = ref([])

onMounted(async () => {
  await loader
    .load()
    .then(google => {
      map.value = google.maps.Map(document.getElementById('map'), {
        center: { lat: -34.397, lng: 150.644 },
        zoom: 8
      })
    })
    .catch(error => {
      console.log(error)
    })
    .then(function () {
    // always executed
    })
})
</script>

<template>
  <div
    id="map"
    class="map"
  />
</template>

<style>
  html,
  body,
  #map {
    height: 100%;
    margin: 0;
    padding: 0;
  }
</style>

但是地图没有显示,只有弹出窗口,地图无法正确加载。在控制台中发生此错误: typeError: this.set不是一个函数。(在'this.set("renderingType",“UNINITIALIZED”)中,'this.set‘是未定义的)有人知道如何让它运行(最好是在<script setup>中)吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-02-23 01:03:14

尝试添加这样的

代码语言:javascript
运行
复制
map.value = new google.maps.Map(document.getElementById('map'), {
        center: { lat: -34.397, lng: 150.644 },
        zoom: 8
      })
票数 1
EN

Stack Overflow用户

发布于 2022-08-12 17:33:42

必须使用id映射在div中指定宽度和高度。

代码语言:javascript
运行
复制
<template>
  <div class="map" id="map" style="width: 300px;height: 200px;" ></div>
</template>
票数 1
EN

Stack Overflow用户

发布于 2022-06-20 04:02:18

如果它不起作用,也试试这个吧:

代码语言:javascript
运行
复制
map.value = new window.google.maps.Map(document.getElementById('map'), {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71181320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档