S
S
Sergey Petrov2020-03-26 20:48:47
JavaScript
Sergey Petrov, 2020-03-26 20:48:47

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>


In general, I get the coordinates,
but they are not correct
, it does not work out to get reliable coordinates
Please help me out

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question