Skip to content

Markers position not refreshing #35

Closed
@polsola

Description

@polsola

Hello! I'm using custom markers and I'm trying to refresh the position every X seconds, currently I've faked it with a timeOut like this:

<template>
<div>
  <GmapMap
    :center="center"
    :zoom="8"
    style="width: 100%; height: 600px"
    >
    <gmap-custom-marker 
        :key="vehicle.id"
        v-for="vehicle in vehicles"
        :marker="vehicle.position"
    >
        <div class="vehicle-marker">
            <img :src="vehicle.avatar" />
        </div>
    </gmap-custom-marker> 
</GmapMap>
</div>
</template>

<style lang="scss">

.vehicle-marker {
    img {
        width: 64px;
        display: block;
    }
}
    
</style>

<script>
export default {
    layout: 'default',
    data() {
        return {
            center: {lat:41.385063, lng:2.173404},
            vehicles: [
                {
                    id: 1,
                    avatar: '##',
                    position: {
                        lat: 41.385063,
                        lng: 2.173404
                    }
                },{
                    id: 2,
                    avatar: '##',
                    position: {
                        lat: 41.930290,
                        lng: 2.254350
                    }
                }
            ]
        }
    },
    mounted() {
        setInterval(function () {
            this.vehicles.forEach(vehicle => {
                var newLat = vehicle.position.lat += (Math.floor(Math.random() * 11) >= 6) ? 0.005 : -0.005
                var newLng = vehicle.position.lng += (Math.floor(Math.random() * 11) >= 6) ? 0.005 : -0.005
                console.log('Vehicle', vehicle.id, newLat, newLng)
                vehicle.position.lat = newLat
                vehicle.position.lng = newLng
            });
            }.bind(this), 2000)
    }
}
</script>

This code works with default markers but custom ones seems not to refresh, it's maybe because I'm using Nuxt.js? I'm importing the library with a plugin and ssr: false to avoid errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions