Through the API, I get data from a third-party service. Response structure:
[ { ... “Latitude”: “<Широта>”, “Longitude”: “<Долгота>”, ... } ] With the help of the php file getdata.php I pass through the array and collect all the data
foreach ($response as $item) { $a = "[".$item['Latitude'].",".$item['Longitude']."]," ; $array = $array.$a ; } $list= substr($array, 0, -1); echo json_encode($list); This is a list of points that I want to display on the map using the Yandex.Maps API.
var myMap = new ymaps.Map('map', { ... points = [ [55.831903,37.411961], [55.763338,37.565466] ], } - How do I transfer the data to the $ list variable in points ?
- Question about the correctness of the code in php? It seems to print the correct data, but is it necessary to do json_encode and is it possible to replace substr ($ array, 0, -1); on something inside foreach ?
var value = <?php echo $string;?>- Bogdan Gudyma