简体   繁体   English

标记更新位置

[英]Marker update position

I'm using web2py on the server side to get google map position values: 我在服务器端使用web2py来获取Google地图位置值:

  window.setInterval(function() {
                {{dic = get_position(1)}}
                var newPos = new google.maps.LatLng({{=dic['ID1']['lat']}}, {{=dic['ID1']['lon']}});
                markers[0].setPosition(newPos);
                testcounter++;}, 4000);

I want to change the position of a marker ( markers[0] ). 我想更改标记的位置( markers[0] )。 The new position for marker is collected, but doesn't update its position on the map. 标记的新位置已收集,但不会更新其在地图上的位置。

The data is collected from get_position() into a python dictionary of dicts and the data is ok.The parameter is a record id for testing purposes. 数据从get_position()收集到get_position()的python字典中,并且数据正常。该参数是用于测试目的的记录ID。

The html generated code, is ok too: html生成的代码也可以:

    window.setInterval(function() {
                var newPos = new google.maps.LatLng(-20.21353, -70.14904);
                markers[0].setPosition(newPos);
                testcounter++;}, 4000);

With testcounter I'm only checking the 4 secs loop. 使用testcounter,我只检查4秒循环。

I have no experience of Python so I can't help with the back-end, but it looks like your best bet is to simply remove and re-instantiate the marker rather than attempting to alter it's position. 我没有Python的经验,所以我对后端无济于事,但是您最好的选择是简单地删除并重新实例化标记,而不是尝试更改其位置。

Alternately merely remove and replace the current marker? 或者仅删除并替换当前标记? Ie: 即:

markers[0].setMap(null);
markers[0].setMap(yourmap);

Though to be honest it would be strange if this solved the issue, but perhaps it needs to be reset in order to pick up the altered value. 虽然说实话,如果这解决了问题会很奇怪,但是也许需要重置它才能获取更改后的值。

Sorry to not be of more help. 抱歉没有更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM