Answer the question
In order to leave comments, you need to log in
How to get coordinates from an address?
Good day.
ymaps.ready(init);
function init() {
var myPlacemark,
myMap = new ymaps.Map('map', {
center: [55.753994, 37.622093],
zoom: 9,
controls: ['zoomControl', 'geolocationControl', 'fullscreenControl', 'routeButtonControl']
}, {
searchControlProvider: 'yandex#search'
});
var suggestView1 = new ymaps.SuggestView('suggest1'); //база адресов
}
$("#suggest1").change(function(){
var t=$("#suggest1").val(); //получаем адрес
//определяем координаты по адресу: Россия, Москва, Свободный проспект, 1Б
ymaps.geocode(t,{results:1}).then(
function(res){ var MyGeoObj = res.geoObjects.get(0);
//извлечение координат
document.getElementById('one').value = MyGeoObj.geometry.getCoordinates();
});
});
})
<!--Этот input, который выдает адрес из базы Яндекс, по мере его ввода-->
<input type="text" class="form-control" name="Address" id="suggest1"><br>
<input type="text" id="one" name="Coordinates" placeholder="Координаты"><br>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question