谷歌地图上的自定义标记

时间:2018-06-05 22:59:20

标签: google-maps vue.js laravel-5.6 vue2-google-maps

问题详情

显示默认图标,我期待标记的自定义图标。我在下面的代码中遗漏了什么吗?

我正在使用Laravel 5.6.12和vue.js并尝试在谷歌地图中显示自定义图标。我的代码在模板下面。

<template>
    <div>        
        <gmap-map
            :center="center"
            :zoom="12"
            style="width:100%;  height: 400px;">
            <gmap-marker
              :key="index"
              v-for="(m, index) in markers"
              :position="m.position">
            </gmap-marker>
        </gmap-map>
    </div>
</template>

JS代码

<script>
    export default {
        data() {
            return { 
                center: { lat: 30.2457963, lng: 75.84207160000005 },
                markers: [],
                places: []
            }
        },
        created() {
            this.markers.push({ 
                 position: this.center, 
                 icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png' 
            });
        },
        methods: {

        }
    }
</script>

2 个答案:

答案 0 :(得分:0)

你试过这个吗?将图标绑定到gmap-marker元素

<gmap-marker
  :key="index"
  v-for="(m, index) in markers"
  :position="m.position">
  :icon="m.icon"   
</gmap-marker>

答案 1 :(得分:0)

我有类似的问题,下面的解决方案有效。就像将:icon="{ url:'./path-/to/-icon.png'}"添加到gmap-marker一样简单。例如,您的脚本应如下所示:

<gmap-marker
     :key="index"
     v-for="(m, index) in markers"
     :position="m.position"
     :icon="{ url:'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'}">
</gmap-marker>
相关问题