Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. <script>
  2. ymaps.ready(init);
  3.  
  4. function init() {
  5. var geolocation = ymaps.geolocation;
  6. var myMap = new ymaps.Map('map', {
  7. center: [55.745508, 37.435225],
  8. zoom: 13
  9. }, {
  10. searchControlProvider: 'yandex#search'
  11. });
  12.  
  13. geolocation.get({
  14. provider: 'yandex',
  15. mapStateAutoApply: true
  16. }).then(function(result) {
  17. result.geoObjects.options.set('preset', 'islands#redCircleIcon');
  18. result.geoObjects.get(0).properties.set({
  19. balloonContentBody: 'Мое местоположение'
  20. });
  21. var firstGeoObject = result.geoObjects.get(0);
  22. console.log('Населенный пункт: %s', firstGeoObject.getLocalities().join(', '));
  23. var cit = ''' + firstGeoObject.getLocalities().join(', ') + ''';
  24. ymaps.route([
  25. cit,
  26. {
  27. point: 'г. Москва Якуба Колоса',
  28.  
  29. type: 'viaPoint'
  30. }
  31.  
  32. ]).then(function(route) {
  33. myMap.geoObjects.add(route);
  34.  
  35. var points = route.getWayPoints(),
  36. lastPoint = points.getLength() - 1;
  37.  
  38. points.options.set('preset', 'islands#redStretchyIcon');
  39.  
  40. points.get(0).properties.set('iconContent', 'Точка отправления');
  41. points.get(lastPoint).properties.set('iconContent', 'Точка прибытия');
  42.  
  43.  
  44. var moveList = 'Трогаемся,</br>',
  45. way,
  46. segments;
  47. // Получаем массив путей.
  48. for (var i = 0; i < route.getPaths().getLength(); i++) {
  49. way = route.getPaths().get(i);
  50. segments = way.getSegments();
  51. for (var j = 0; j < segments.length; j++) {
  52. var street = segments[j].getStreet();
  53. moveList += ('Едем ' + segments[j].getHumanAction() + (street ? ' на ' + street : '') + ', проезжаем ' + segments[j].getLength() + ' м.,');
  54. moveList += '</br>'
  55. }
  56. }
  57. moveList += 'Останавливаемся.';
  58. // Выводим маршрутный лист.
  59. $('#list').append(moveList);
  60. }, function(error) {
  61. alert('Возникла ошибка: ' + error.message);
  62. });
  63. });
  64. }
  65.  
  66.  
  67. </script>";
  68.  
  69. geolocation.get({
  70. provider: 'yandex',
  71. mapStateAutoApply: true
  72. }).then(function(result) {
  73. result.geoObjects.options.set('preset', 'islands#redCircleIcon');
  74. result.geoObjects.get(0).properties.set({
  75. balloonContentBody: 'Мое местоположение'
  76. });
  77. var firstGeoObject = result.geoObjects.get(0);
  78. var cit = firstGeoObject.getAddressLine;
  79. alert(cit);
  80.  
  81. <script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU"></script>
  82. print "..."; // Ваш код
  83. <div id="map"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement