Javascript 移动标记谷歌地图API
我正在使用谷歌地图API,我想移动制造商。 我使用以下代码:Javascript 移动标记谷歌地图API,javascript,jquery,google-maps,Javascript,Jquery,Google Maps,我正在使用谷歌地图API,我想移动制造商。 我使用以下代码: marker.setPosition( new google.maps.LatLng(driver.location_latitude, driver.location_longitude ) ); 问题是它复制了maker,而不是仅仅移动它。请尝试此代码 marker.setMap(null); marker.setPosition( new google.maps.LatLng(driver.location_latitude
marker.setPosition( new google.maps.LatLng(driver.location_latitude, driver.location_longitude ) );
问题是它复制了maker,而不是仅仅移动它。请尝试此代码
marker.setMap(null);
marker.setPosition( new google.maps.LatLng(driver.location_latitude, driver.location_longitude ) );
marker.setMap(map);
请注意,
map
是您的地图对象。只需删除旧标记。.您没有发布足够的代码来解释问题。您发布的代码应移动标记。有件事你没有告诉我们。不知道你为什么认为这很重要。如果marker是google.maps.marker对象,setPosition应该可以工作。@geocodezip我测试了setPosition()
方法,它可以正常工作,但有时当我使用setMap(null)和setMap(map)
方法之前和之后的setPosition()
方法时,marker会隐藏在map中,这是什么意思“有时标记隐藏在地图中”?听起来不像原始问题所问的问题(这与原始问题“移动标记”有什么关系)。