Answer the question
In order to leave comments, you need to log in
Tag: getting coordinates and address when dragging or clicking (Yandex API)?
Hello. Actually, straight to the point ... There is a code
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map("map", {
center: [55.76, 37.64],
zoom: 10
}, {
searchControlProvider: 'yandex#search'
});
/* Начальный адрес метки */
var address = 'Россия, Москва, Тверская, д. 7';
ymaps.geocode(address).then(function(res) {
var coord = res.geoObjects.get(0).geometry.getCoordinates();
var myPlacemark = new ymaps.Placemark(coord, null, {
preset: 'islands#blueDotIcon',
draggable: true
});
/* Событие dragend - получение нового адреса */
myPlacemark.events.add('dragend', function(e){
var cord = e.get('target').geometry.getCoordinates();
$('#ypoint').val(cord);
ymaps.geocode(cord).then(function(res) {
var data = res.geoObjects.get(0).properties.getAll();
$('#address').val(data.text);
});
});
myMap.geoObjects.add(myPlacemark);
myMap.setCenter(coord, 15);
});
}
Answer the question
In order to leave comments, you need to log in
Track all clicks on the map
map.events.add('click', function (e) {
get click coordinates
var coords = e.get('coords');
move marker to new coordinates
myPlacemark ygeometry.setCoordinates(coords );
}) ;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question