K
K
kentos2019-01-30 11:00:11
Yandex maps
kentos, 2019-01-30 11:00:11

How to determine a place by a point on the map?

How to determine the address by moving point on the map?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-01-30
@kentos

Listen for dragend event, perform reverse geocoding :

<div>{{ address }}</div>
<div ref="map"></div>

data: () => ({
  coords: [ ... ],
  address: '',
}),
mounted() {
  ymaps.ready(() => {
    const map = new ymaps.Map(this.$refs.map, { ... });

    const marker = new ymaps.Placemark(this.coords, {}, {
      draggable: true,
    });

    marker.events.add('dragend', e => {
      this.coords = e.get('target').geometry.getCoordinates();
    });

    map.geoObjects.add(marker);

    this.$watch('coords', {
      immediate: true,
      handler(coords) {
        ymaps.geocode(coords).then(r => {
          this.address = r.geoObjects.get(0).properties.get('name');
        });
      },
    });
  });
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question