dir.by  
Поиск >>

Компьютер, программы
→
Yandex services for Web sites (visitor counter, street map, language translator, contextual advertising, ...)
 Как добавить Yandex карту на сайт 
посмотрели 9852 раз
обновлено: 5 September 2018
Вариант 1 (это новый, лучший вариант)
  Html     Создадим новый файл 1.html напишем код:
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript">
</script>

<div id='MyMap1' style='width:1px; height:1px;'>

<script type='text/javascript'>

     // Когда yandex библиотека загрузится, то вызовется моя функция initYMaps
     ymaps.ready(initYMaps);

     function initYMaps()
     {
          // создание Yandex карты
          var myMap = create_yandex_map('MyMap1', 640, 480)
    
          // добавляем 1-ую точку
          add_yandex_point(myMap, 27.458004, 53.907726, 'vvv');
    
          // добавляем 2-ую точку
          add_yandex_point(myMap, 27.458004, 53.997726, 'aaa');
    
          // указываем центр и zoom Yandex карты
          center_and_zoom_yandex_map(myMap, 27.458004, 53.952726, 11);
     }

     function create_yandex_map(map_id, width, height)
     {
          // get div
          var elemDiv = document.getElementById(map_id);
          if (elemDiv==null)
               return null;
          elemDiv.style.width = width;
          elemDiv.style.height = height;
         
          // create map
          var myMap = new ymaps.Map(map_id,
          {
               center: [0, 0], // default center
               zoom: 0 // default zoom
          });

          return myMap;
     }

     function add_yandex_point(myMap, latitud, longit, title)
     {
          // add label
          var myPlacemark = new ymaps.Placemark([longit, latitud],
               {
                    balloonContentHeader: title,
                    balloonContentBody: '',
                    balloonContentFooter: ''
               }
          );
          myMap.geoObjects.add(myPlacemark);
     }

     function center_and_zoom_yandex_map(myMap, latitud, longit, map_zoom)
     {
          if (map_zoom==0)
               map_zoom = 16;

          // set center & zoom
          myMap.setCenter([longit, latitud], map_zoom);
     }
</script>
Example we look, we test
Вариант 2 (старый вариант через API-ключ)
Чтобы добавить Yandex карту на сайт нужно:
1) зайти по ссылке http://api.yandex.ru/maps/form.xml и войти в Yandex
Результат
2) Написать имя сайта и нажать получить ключ
Результат
3) Написать код на html. Заменить MAP_API_CODE на ваш

Пример заменить MAP_API_CODE на
AHCLlVkBAAAAXDdyZQIAYcLDFHGFHGFHGHFGFHGHFHGHFGFHFGHGFHFGAADXresjnAiPZsWEskSwfH3BfBcUEg==

На каждый сайт yandex создает свой ключ вам нужно использовать свой API ключ.
  Html     Пример
<script src='http://api-maps.yandex.ru/1.1/index.xml?key=MAP_API_CODE&modules=pmap' type='text/javascript'></script>

<div id='my_map_element' style='width:100px; height:100px;'></div>

<script type='text/javascript'>
     function add_yandex_point(map_id, latitud, longit, title, map_zoom)
     {
          if (map_zoom==0)
               map_zoom = 16;

          // get div
          var elemDiv = document.getElementById(map_id);
          elemDiv.style.width = '640px';
          elemDiv.style.height = '480px';
         
          // create map
          var xmap = null;
          xmap = new YMaps.Map(elemDiv);
          xmap.addControl(new YMaps.SmallZoom());

          // add coordinate
          var points = new Array();
          points.push(new YMaps.GeoPoint(latitud, longit));

          // add title
          var titles = new Array();
          titles.push(title);

          var geocoder = new YMaps.Geocoder(new YMaps.GeoPoint(points[0].lat, points[0].lng), {results: 1});

          var bounds = new YMaps.GeoCollectionBounds(points);
          xmap.setCenter(bounds.getCenter(), map_zoom, YMaps.MapType.PMAP);

          xmap.openBalloon(points[0], titles[0]);
     }

     add_yandex_point('my_map_element', 27.53131665, 53.920020916, 'Привет'/*заголовок*/, 12/*map zoom*/);
</script>
Example we look, we test
 
← Previous topic
How to add a visit counter (Yandex Metrica) to your website
 
Next topic →
Yandex Translate API (language translator)
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
Yandex Metrica (information about site visits)
• Information about site visits (how many visits, from which devices) Yandex Metrica
• How to add a visit counter (Yandex Metrica) to your website
Yandex Map (cities, streets)
• How to add a Yandex map to a website
Yandex Translate
• Yandex Translate API (language translator)
Yandex Direct (contextual advertising)
• Yandex Direct (what is contextual advertising?)
Yandex Direct API (program code for managing advertising campaigns)
• Access to Yandex Direct API (test environment)
• Sandbox (test companies) Yandex Direct API
• Example "List of companies" php and Yandex Direct API (test environment)
• Access to Yandex Direct API
• Establishment of the Company (on the direct.yandex.ru website)
• Financial Token
Yandex Advertising Network (YAN)
• Yandex Advertising Network (description) | How to join | Customize
• Adding Yandex ads to your site (vertical poster with 2 ads)
• Adding Yandex ads to your site (6 ads in a line, horizontal)
• Add a second site to the Yandex Advertising Network
Yandex Webmaster (site indexing, site links internal and external, etc.)
• What is Yandex Webmaster?
• How to add Yandex Webmaster to your website
Yandex Mail
• Yandex Mail (description)
Alice Talking Speaker Yandex
• I bought a Yandex speaker mini "Alice" and I want to connect it (I use an Android phone or iPhone)
• Column mini "Alice" view payment on the yandex website (you can change the plan, payment method)
Additionally
• How do I see the SQI (Site Quality Index) value for any site?

  Ваши вопросы присылайте по почте: info@dir.by