D
D
Denis Kiselev2016-12-06 15:52:57
Yandex
Denis Kiselev, 2016-12-06 15:52:57

How to generate json file for yandex map on wordpress?

Hello!
Please tell me how to solve the problem. I'm making a social map on WordPress, all objects in a custom post type, where you can enter all the object's coordinates and dt. The question is how then to display all these objects on the map, there are a large number of them. From the manuals, I realized that the labels need to be loaded from a YMapsML file or json. BUT how to pre-generate this file???
Tell me, in which direction at least to look? Experience in this zero, I do not know what side to approach.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Kiselev, 2016-12-06
@kiselev-webmaster

resolved the issue. Might be useful to someone:

<?php 
  require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
  global $post;
  global $wpdb;
?>
<?php $markers = get_posts ('post_type=markers&order=ASC'); ?> 
<?php $arr = array(); ?>
  <?php if ($markers) :?>
    <?php foreach ($markers as $post) : setup_postdata ($post); ?>
      <?php 
        $arr[get_the_ID()]['type'] = 'Feature';
        $arr[get_the_ID()]['id'] = '0'; 
        $arr[get_the_ID()]['geometry']['type'] = 'Point'; 
        $arr[get_the_ID()]['geometry']['coordinates'] = array(55.831903, 37.411961); 
        $arr[get_the_ID()]['properties']['balloonContent'] = 'Содержимое балуна';
        $arr[get_the_ID()]['properties']['clusterCaption'] = 'Еще одна метка'; 
        $arr[get_the_ID()]['properties']['hintContent'] = 'Текст подсказки';
      ?>
    <?php endforeach; ?>
  <?php endif; ?>
<?php wp_reset_postdata(); ?>

<?php
  $array = array(
    "type" => "FeatureCollection",
    "features" => array_values($arr)
  );
?>
<?php echo json_encode($array); ?>

the code is not ideal, comments and remarks are welcome)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question