1

I'm using web2py on the server side to get google map position values:

  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]). 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.

The html generated code, is ok too:

    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.

4

1 に答える 1

0

私はPythonの経験がないので、バックエンドを手伝うことはできませんが、マーカーの位置を変更するのではなく、単にマーカーを削除して再インスタンス化するのが最善の策のようです。

または、現在のマーカーを削除して置き換えるだけですか?すなわち:

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

正直なところ、これで問題が解決したかどうかはおかしいですが、変更された値を取得するには、おそらくリセットする必要があります。

これ以上お役に立てず申し訳ありません。

于 2012-12-05T13:09:13.687 に答える