Answer the question
In order to leave comments, you need to log in
How to get user coordinates in yandex maps?
There is a code:
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map(\"map\", {
center: [".$this->coords."],
zoom: ".$this->zoom."
});
var geolocation = ymaps.geolocation,
coords = [geolocation.latitude, geolocation.longitude];
//кнопка
var myButton = new ymaps.control.Button('Проложить маршрут');
myButton.events
.add('click', function () {
ymaps.route([
[".$this->coords."],
coords,
]).then(function (route) {
myMap.geoObjects.add(route);
var points = route.getWayPoints(),
lastPoint = points.getLength() - 1;
points.options.set('preset', 'twirl#redStretchyIcon');
points.get(0).properties.set('iconContent', 'Точка отправления');
points.get(lastPoint).properties.set('iconContent', 'Точка прибытия');
}, function (error) {
alert('Возникла ошибка: ' + error.message);
});
});
myMap.controls.add(myButton);
}
var geolocation = ymaps.geolocation,
coords = [geolocation.latitude, geolocation.longitude];
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