Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://yandex.st/jquery/2.2.3/jquery.min.js" type="text/javascript"></script>
- <script charset="utf-8" src="https://api-maps.yandex.ru/1.1/index.xml" type="text/javascript"></script>
- <div style="width:600px;height:400px" id="YMapsID" class="YMaps YMaps-cursor-grab"></div>
- <? $pint = '58.211748';?>
- <script type="text/javascript">
- var points_json = '{"Points":[{"MapPoinName": "Город 1","MapPointPopulation": 125000,"MapPointCoordinates": "<?=$pint?>, 59.979321"}, {"MapPoinName": "Город 2","MapPointPopulation": 105000,"MapPointCoordinates": "51.221748, 53.929321"}]}';
- var points = $.parseJSON(points_json);
- // Создание обработчика для события window.onLoad
- YMaps.jQuery(function () {
- // Создание экземпляра карты и его привязка к созданному контейнеру
- var map = new YMaps.Map(YMaps.jQuery("#YMapsID")[0]),
- // Центр карты
- center,
- // Масштаб
- zoom = 10;
- // Получение информации о местоположении пользователя
- if (YMaps.location) {
- center = new YMaps.GeoPoint(YMaps.location.longitude, YMaps.location.latitude);
- if (YMaps.location.zoom) {
- zoom = 3;
- }
- map.openBalloon(center, "Место вашего предположительного местоположения:<br/>"
- + (YMaps.location.country || "")
- + (YMaps.location.region ? ", " + YMaps.location.region : "")
- + (YMaps.location.city ? ", " + YMaps.location.city : "")
- )
- }else {
- center = new YMaps.GeoPoint(37.64, 55.76);
- }
- for(var i=0;i < points.Points.length;i++){
- var tmp_points = points.Points[i]['MapPointCoordinates'].split(', ');
- var desc = points.Points[i]['MapPointPopulation'];
- var placemark = new YMaps.Placemark(new YMaps.GeoPoint(tmp_points[0],tmp_points[1]));
- placemark.description = "point "+i+" description" + desc;
- map.addOverlay(placemark);
- center = new YMaps.GeoPoint(tmp_points[0], tmp_points[1]);
- }
- // Рисуем карту
- map.setCenter(center, zoom);
- });
- </script>
Add Comment
Please, Sign In to add comment