As to add in JS the index of maps from two php of the masses at coordinates



  • I'm trying to add a map of objects to the code. If it's manual, it's fine. I can't understand how to automatically add the required number of objects with the marks, latitude and longitude. The code of one mark looks like it.

    velomig = new ymaps.Placemark([55.740005,37.861097], {
        balloonContent: '<img src="/images/MapBannersDealers/velomig.jpg">',
        clusterCaption: 'Веломиг'
    }, getPointOptions());
    

    Name of mark, coordinates, contents of the balloon and signature of the cluster.

    How do I make a cycle that would cross all the coordinates from the masses and return the objects with the set values, something like

    for (i = 0, i<longitude.length, i++ ){  
        name[i] = new ymaps.Placemark([longitude[i],latitude[i]],{
            balloonContent: ballon[i],
            clusterCaption: clusterCaprion[i]
        }, getPointOptions());
    } 
    


  • Don't mix PHP and JavaScript, make your mass and put it on the page with standard function php- http://php.net/manual/ru/function.json-encode.php Like:

    <?php
    

    $dataArray = [
    [
    'coords' => [55.800434123328664,37.913230695312514],
    'title' => "Метка 1"
    ],
    [
    'coords' => [55.707629064640194,37.469839704628086],
    'title' => "Метка 2"
    ],
    [
    'coords' => [55.64865482240896,37.656607282753086],
    'title' => "Метка 3"
    ],
    ];

    ?>

    <script type="application/json" id="map-points"><?=json_encode($dataArray)?></script>

    On the way out, it must be:

    <script type="application/json" id="map-points">
    [
    {
    "cords": [55.800434123328664,37.913230695312514],
    "title": "Метка 1"
    },
    {
    "cords": [55.707629064640194,37.469839704628086],
    "title": "Метка 2"
    },
    {
    "cords": [55.64865482240896,37.656607282753086],
    "title": "Метка 3"
    }
    ]
    </script>

    Then pull these data out and take a cycle.

    A working example here. https://codepen.io/lukas-pierce/pen/xgoYEY




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2