Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- ymaps.ready(init);
- function init() {
- var geolocation = ymaps.geolocation;
- var myMap = new ymaps.Map('map', {
- center: [55.745508, 37.435225],
- zoom: 13
- }, {
- searchControlProvider: 'yandex#search'
- });
- geolocation.get({
- provider: 'yandex',
- mapStateAutoApply: true
- }).then(function(result) {
- result.geoObjects.options.set('preset', 'islands#redCircleIcon');
- result.geoObjects.get(0).properties.set({
- balloonContentBody: 'Мое местоположение'
- });
- var firstGeoObject = result.geoObjects.get(0);
- console.log('Населенный пункт: %s', firstGeoObject.getLocalities().join(', '));
- var cit = ''' + firstGeoObject.getLocalities().join(', ') + ''';
- ymaps.route([
- cit,
- {
- point: 'г. Москва Якуба Колоса',
- type: 'viaPoint'
- }
- ]).then(function(route) {
- myMap.geoObjects.add(route);
- var points = route.getWayPoints(),
- lastPoint = points.getLength() - 1;
- points.options.set('preset', 'islands#redStretchyIcon');
- points.get(0).properties.set('iconContent', 'Точка отправления');
- points.get(lastPoint).properties.set('iconContent', 'Точка прибытия');
- var moveList = 'Трогаемся,</br>',
- way,
- segments;
- // Получаем массив путей.
- for (var i = 0; i < route.getPaths().getLength(); i++) {
- way = route.getPaths().get(i);
- segments = way.getSegments();
- for (var j = 0; j < segments.length; j++) {
- var street = segments[j].getStreet();
- moveList += ('Едем ' + segments[j].getHumanAction() + (street ? ' на ' + street : '') + ', проезжаем ' + segments[j].getLength() + ' м.,');
- moveList += '</br>'
- }
- }
- moveList += 'Останавливаемся.';
- // Выводим маршрутный лист.
- $('#list').append(moveList);
- }, function(error) {
- alert('Возникла ошибка: ' + error.message);
- });
- });
- }
- </script>";
- geolocation.get({
- provider: 'yandex',
- mapStateAutoApply: true
- }).then(function(result) {
- result.geoObjects.options.set('preset', 'islands#redCircleIcon');
- result.geoObjects.get(0).properties.set({
- balloonContentBody: 'Мое местоположение'
- });
- var firstGeoObject = result.geoObjects.get(0);
- var cit = firstGeoObject.getAddressLine;
- alert(cit);
- <script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU"></script>
- print "..."; // Ваш код
- <div id="map"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement