Task every 30 seconds, update the coordinates of the label, and display them on the map, without rebooting.

ymaps.ready(init); function init() { // Создание экземпляра карты. var myMap = new ymaps.Map('map', { center: [50.443705, 30.530946], zoom: 14, type: "yandex#map", controls: ["smallMapDefaultSet", "trafficControl"] }), objectManager = new ymaps.ObjectManager(); myMap.geoObjects.add(objectManager); var fn2 = function() { $.ajax({ url: "coords.php" }).done(function(data) { objectManager.add(data); }); } var intervalID = setTimeout(fn2, 300); } 

Labels do not load and do not move, how to download, overwrite (update)?

Tag Code

 myPlacemark15318787 = new ymaps.Placemark([x, y], { hintContent: 'HD', balloonContent: 'HD' }, { iconLayout: 'default#imageWithContent', iconImageHref: 'images/hdb6.svg', iconImageSize: [30, 30], iconImageOffset: [-15, -15], iconContentOffset: [28, 1] }), myMap.geoObjects.add(myPlacemark15318787); 
  • I want to remind you that according to the terms of use, I quote: "When using the free version of the API, you cannot: Track vehicles, people and other objects in real time." - flapenguin
  • Our company has a license - Andrew

1 answer 1

If you use OM and always return all data that should be displayed on the map, then you need to delete the OM from the map and add it again:

 $.ajax({ url: "coords.php" }).done(function(data) { myMap.geoObjects.remove(objectManager); objectManager = new ymaps.ObjectManager(); objectManager.add(data); myMap.geoObjects.add(objectManager); }); 

You also need to see that your application does not violate the terms of use https://tech.yandex.ru/maps/doc/jsapi/2.1/terms/index-docpage/

  • Do you think it is optimal to use OM for this task? - Andrew
  • And if more, then what is the problem? Without a detailed description it is not clear what is best to use. - se0ga
  • Every 30 seconds I get the coordinates from the sensors on my cars. Receives php a script and forms json. The goal is to display a moving car on the map. I am aware of the Yandex license - Andrei
  • the number of tags is unclear, but I would first try to add regular tags to the map and update their coordinates via placemark.geometry.setCoordinates () then I’d already look for another way - se0ga pm
  • Found no examples of placemark.geometry.setCoordinates (). Label code indicated in the first post. Can you sketch at least in which direction to go - Andrei