📜 ⬆️ ⬇️

Automating the output of the Yandex.Maps widget on the 1C Bitrix platform

Recently, not on my own, I had to use 1C Bitrix. Not to say that I got an aesthetic pleasure from working with the system, but I expected the worst. So the problems are:



After another editing of this page (changing the information and adding new locations), it seemed to me that this approach was not entirely logical and that this process should be optimized.

The goal was to automate the process of displaying the widget maps. The following tasks were set for implementation:
')

The table with the information for the widget is the following:
FieldData type
IDint
Namevarchar (30)
Addresstext
yandex_latvarchar (20)
yandex_lonvarchar (20)
LATvarchar (20)
LONvarchar (20)

The location determination was given to the Yandex geocoder . It was not immediately clear how the coordinates for the widget are formed. It turned out that the coordinates are obtained from the upper boundary of the area within which the object is recommended to be shown on the map and the position of the object. Having understood, the following script was compiled:

<?php //  XML        function get_XML($adress){ $xml = simplexml_load_file('https://geocode-maps.yandex.ru/1.x/?geocode='.$adress); return $xml; } //  $adr = '. , . , . 52 '; $name_adr = ''; $urlXML = 'https://geocode-maps.yandex.ru/1.x/?geocode='.$adr; // XML  $array = get_XML($adr); //   $pos = $array->GeoObjectCollection->featureMember['0']->GeoObject->Point->pos; echo "<b>pos</b>: $pos \n"; //  ,        $upperCorner = $array->GeoObjectCollection->featureMember['0']->GeoObject->boundedBy->Envelope->upperCorner; echo "<b>upperCorner</b>: $upperCorner \n"; //  ,        $lowerCorner = $array->GeoObjectCollection->featureMember['0']->GeoObject->boundedBy->Envelope->lowerCorner; echo "<b>lowerCorner</b>: $lowerCorner \n"; //      explode $posArr = explode(" ",$pos); $posLeft = explode(".",$posArr[0]); $posRight = explode(".",$posArr[1]); $upperCornerArr = explode(" ",$upperCorner); $upperCornerLeft = explode(".",$upperCornerArr[0]); $upperCornerRight = explode(".",$upperCornerArr[1]); $lowerCornerArr = explode(" ",$lowerCorner); $lowerCornerLeft = explode(".",$lowerCornerArr[0]); $lowerCornerRight = explode(".",$lowerCornerArr[1]); $urlMap = "https://maps.yandex.ru/?text=".$posRight[0].'.'.$posRight[1].$upperCornerRight[0].$upperCornerRight[1].' '.$posLeft[0].'.'.$posLeft[1].$upperCornerLeft[0].$upperCornerLeft[1]; /* LAT - RIGHT LON - LEFT */ $yandex_lat = $posRight[0].'.'.$posRight[1].$upperCornerRight[0].$upperCornerRight[1]; $yandex_lon = $posLeft[0].'.'.$posLeft[1].$upperCornerLeft[0].$upperCornerLeft[1]; $LON = $posLeft[0].'.'.$posLeft[1].$lowerCornerLeft[0].$lowerCornerLeft[1]; $LAT = $posRight[0].'.'.$posRight[1].$lowerCornerRight[0].$lowerCornerRight[1]; $TEXT = $name_adr; ?> 

The same script on JS

After receiving the coordinates, the data is recorded in the database. Thus, 2 problems solved.

And finally, to save the consumed user resources, slideToggle was used:

 <script type="text/javascript"> function slideTopic(comments,titleTopic) { $(comments).slideToggle(250); if ($(titleTopic).attr('title')=='  ') $(titleTopic).attr('title','  '); else $(titleTopic).attr('title','  '); }; </script> 

Source: https://habr.com/ru/post/275021/


All Articles