Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Adding Multiple Markers on Vue JS Google Maps

I have Google Maps embedded on Vue JS code. But I want to show multiple markers using latitude and longitude on that map. Any idea on how to do that? Here is my code.

Maps.vue

<template>
    <card type="plain" title="Google Maps">
      <div id="map" class="map">
      </div>
    </card>
</template>
<script>
export default {
  mounted() {
    let myLatlng = new window.google.maps.LatLng(40.748817, -73.985428);
    let mapOptions = {
      zoom: 13,
      center: myLatlng,
      scrollwheel: false, //we disable de scroll over the map, it is a really annoing when you scroll through page
      styles: [{
        "elementType": "geometry",
        "stylers": [{
          "color": "#1d2c4d"
        }]
      },
        {
          "elementType": "labels.text.fill",
          "stylers": [{
            "color": "#8ec3b9"
          }]
        },
        {
          "elementType": "labels.text.stroke",
          "stylers": [{
            "color": "#1a3646"
          }]
        },
        {
          "featureType": "water",
          "elementType": "labels.text.fill",
          "stylers": [{
            "color": "#4e6d70"
          }]
        }
      ]
    };
    let map = new window.google.maps.Map(
      document.getElementById("map"),
      mapOptions
    );

    let marker = new window.google.maps.Marker({
      position: myLatlng,
      title: "Hello World!"
    });

   
    marker.setMap(map);
  }
};
</script>

How can I display multiple markers on this google map? Any advice or tips would be really helpful. Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use the gmap-vue plugin for VueJS to add multiple markers by clicking on the map.

First, initialize your Google Map, and make sure to add an array of markers: [] that will contain all the markers that you will be adding on the map:

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


export default {
  name: "GoogleMap",
  data() {
    return {
      center: { lat: 45.508, lng: -73.587 },
      markers: [],
    };
  },
  
};

You can add markers by calling the @click="addMarker" event on <gmap-map>. Then, on the your methods you can add the addMarker(event) function where you should be able to get the click coordinates from the map. You can now

Here is what it looks like:

methods: {
    addMarker(event) {
      const marker = {
        lat: event.latLng.lat(),
        lng: event.latLng.lng(),
      };
      console.log(marker);
      this.markers.push({ position: marker });
      this.$refs.mmm.panTo(marker);
      //this.center = marker;
  },
},

Here is a working codesandbox for your reference, just put your API key on the main.js file: https://codesandbox.io/s/gifted-fast-b41ps

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use- but you don't need any plug-in. It doesn't really save time in this use-case imho.

With the standard implementation it would look something like that:

this.yourPOIs.forEach(poi => {
    var myLatLng = { lat: poi.latitude, lng: poi.longitude };
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: this.myMap,
        title: poi.annotation
        // you can also add data here with key names that are not in use like for example "uuid: 1" so you can access that data later on if you click on markers or iterate through them
    });
    marker.addListener('click', function() {
        console.log(marker.uuid); // if you want to react on clicking on a marker
    });
    this.addedMarkers.push(marker);
});

myMap being the map object written in a local variable instead of writing it in a let-variable (you will probably need to access the map later on so you better safe them in the local data of the component or your vuex store).

That's also why i pushed the markers in an array of the component. By that you can later on do this to delete the markers again (for e.g. updating the map):

this.addedMarkers.forEach(marker => {
     marker.setMap(null);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda