Answer the question
In order to leave comments, you need to log in
How to center the map in Yandex map according to the coordinates passed to it?
Good afternoon friends.
There is a Yandex map and points on the map, which are set through the Bitrix admin panel. The map is centered on the coordinates specified at the beginning, next to the map, the list displays the addresses of points, in their attributes the coordinates of the point are written. Tell me how, when you click on the same point, insert its coordinates into the map?
When I click on an element, I pull out the coordinates from the attribute (58.90741,30.16064), but how can I insert them?
Card code:
<div class="address-tab-item">
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
<script type="text/javascript">
ymaps.ready(init);
function init () {
var myMap = new ymaps.Map("map", {
center: [57.9204 ,33.3362],
zoom: 12
}, {
searchControlProvider: 'yandex#search'
}),
// Создаем геообъект с типом геометрии "Точка".
myGeoObject = new ymaps.GeoObject();
myMap.geoObjects
<?foreach($arResult["ITEMS"] as $arItems):?>
.add(new ymaps.Placemark([<?=$arItems["PROPERTY_76_VALUE"]?>], {
iconCaption: '<?=$arResult["CONTACTS_TYPE"][$arItems["PROPERTY_67_ENUM_ID"]]?> <?=$arItems["NAME"]?>'
}, {
preset: 'islands#blueCircleDotIconWithCaption'
}))
<?endforeach;?>
;
}
</script>
<div id="map" style="width: 100%; height: 550px"></div>
</div>
Answer the question
In order to leave comments, you need to log in
Everything turned out to be much easier. Manipulations with the map must be registered after its initialization, in the script code itself, then everything will be fine.
In my case, the code would be like this (inside the map script):
$('.address .place').on('click', function(){
var setCor = $(this).attr('pointcor').split(',');
// распарсили строку по ',' в массив
myMap.setCenter(setCor, 16);
// передали в функию новые координаты с нужным зумом
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question