对于自定义位置指示器,我使用 Here SDK 提供的 MapMarker。该位置是通过信标获得的。在某些时候,我仍然通过信标收到地理坐标形式的新位置数据,但 map 标记的定位停止并保持在某个位置。一段时间后,假设是 100m,它会更新位置,但随后再次卡住。我在实现过程中错过了什么吗?
if (mPositionIndicator.getCoordinate() != geoCoordinate)
mPositionIndicator.setCoordinate(geoCoordinate);
地理坐标每秒或更短时间更新一次。
我可以看到新位置...但 map 标记仍保留在某个旧位置。
我传递给 map 标记的geoCooperative
看起来像这样:new GeoCooperative(52.xxxxxx, 13.xxxxxx)
我尝试使用removeMapObject和addMapObject更新位置,但当传递新位置时它仍然不会更新。
更新: 更多信息。我使用其他一些框架从信标获取位置数据并将该数据设置为 map 标记。
最佳答案
要为MapMarker
设置新位置,您不必再次调用addMapObject()
。设置新位置就足够了。例如,以下代码将创建一个 MapMarker
,它每 100 毫秒不断向北移动:
new Thread() {
public void run() {
try {
while(true) {
if (m_marker == null) {
m_latitude = 52.5;
Image image = new Image();
image.setBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.image));
m_marker = new MapMarker(new GeoCoordinate(m_latitude, 13.4), image);
m_hereMap.addMapObject(m_marker);
}
// move marker north
m_marker.setCoordinate(new GeoCoordinate(m_latitude += 0.00001, 13.4));
sleep(100);
}
} catch (InterruptedException e) {}
}
}.start();
因此我建议隔离该问题。如果您使用 Beacons 接收更新的室内位置或 HERE 的 PositioningManager
,应该没有关系。
此外,在您的实现中,比较 GeoCooperative
实例而不是比较纬度或经度是否不同看起来有点可疑。最好使用 geoCoordination1.equals(geoCoordination2)。
关于android - MapMarker.setCooperative() 停止更新位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44588860/