如何更新地图上的位置并将标记移动到更新的位置 [英] How to update location on map and move the marker to the updated location

查看:230
本文介绍了如何更新地图上的位置并将标记移动到更新的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用数据库中的位置(纬度,长度)数据创建和显示地图。

setInterval已使用,但地图和标记没有变化。

我需要跟踪数据库中更新lat的GPS设备。

从数据库读取新数据(lat,long)时,标记应该设置为新位置的动画。

代码的目标是在地图上显示GPS设备的实时位置。



我将目前的代码放在下面..



请帮帮我,任何人。



谢谢。



我尝试过:



I am able to create and display map with location(lat,long) data from database.
"setInterval" used but the map and marker is not changing.
I need to track GPS device with updated lat,long from the database.
upon new data(lat,long) read from the database, the marker should animate to the new location.
objective of the code is to show the realtime position of GPS device on the map.

I am putting my present code below..

please help me,anybody.

Thanks.

What I have tried:

var map;
           var marker;

           function LoadMap()
           {
                <?php include 'latlongmap.php';?>
                SetMap(fetchedlatlong);
           }


           function SetMap(latlong)
           {
              map = L.map('map').setView(latlong, 12);

              mapLink = 'OpenStreetMap';
              L.tileLayer(
           'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
           attribution: 'Map data © ' + mapLink,
           maxZoom: 18,
           }).addTo(map);
               marker = L.marker(latlong).addTo(map);
               layer.bindPopup('LatLng: ' + layer.getLatLng()).openPopup();
           }



           setInterval(LoadMap,5000);

推荐答案

Quote:

function LoadMap()
{
    <?php include 'latlongmap.php';?>
    SetMap(fetchedlatlong);
}



该代码将呈现 latlongmap.php 文件的输出< b> ONCE ,首次请求页面时。在重新加载页面之前,该输出不会改变。



如果要在不重新加载页面的情况下从服务器加载数据,则需要发出AJAX请求。

使用入门 - 开发者指南| MDN [ ^ ]

获取文档 [ ^ ]


That code will render the output of the latlongmap.php file ONCE, when the page is first requested. That output will not change until you reload the page.

If you want to load data from the server without reloading the page, then you need to make an AJAX request.
Getting Started - Developer guides | MDN[^]
fetch documentation[^]


这篇关于如何更新地图上的位置并将标记移动到更新的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆