我需要能够使用Here map android sdk显示移动的汽车。 在当前版本中是否可能?我尝试删除并在渲染类循环逻辑中添加地图标记对象,如下所示;
// this is a render like loop which is called in each 1 secs
public void update(Map map, float deltaTime) {
float displacement = mCars.get(0).getVelocity() * deltaTime;
float delta = displacement / ((float) Math.sqrt(2));
MapMarker mapMarker = new MapMarker();
Image image = new Image();
image.setBitmap(mCars.get(0).getIcon().toBitmap());
mapMarker.setCoordinate(mCars.get(0).getCoordinate());
mapMarker.setIcon(image);
// remove old coordinate
map.removeMapObject(mapMarker);
mCars.get(0).addDelta(delta);
mapMarker.setCoordinate(mCars.get(0).getCoordinate());
map.addMapObject(mapMarker);
}
removeMapObject()
似乎无法正常工作。有移动地图对象的想法吗?
答案 0 :(得分:0)
这里的问题是创建每个标记并删除它们并重新添加它们。 渲染循环如下;
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button1:
// button 1 is click
break;
case R.id.button2:
// button 2 is click
break;
case R.id.button3:
// button 3 is click
break;
default:
break;
}
}
// this is a render like loop which is called in each 1 secs
public void update(Map map, float deltaTime) {
Timber.d("Before coordinate: %f %f", mCars.get(0).getCoordinate().getLatitude(), mCars.get(0).getCoordinate().getLongitude());
map.removeMapObject(mCars.get(0).getMarker());
mCars.get(0).addDelta(deltaTime);
map.addMapObject(mCars.get(0).getMarker());
Timber.d("Update call, delta time: %f", deltaTime);
}
调用应更新标记坐标及其自己的坐标;
addDelta()
最后,public void addDelta(float deltaTime) {
if (mDestination.equals(mCoordinate)) {
return;
}
double deltaLatitude = mDestination.getLatitude() - mCoordinate.getLatitude();
double deltaLongitude = mDestination.getLongitude() - mCoordinate.getLongitude();
double lat = getCoordinate().getLatitude() + (0.01 * deltaLatitude);
double lng = getCoordinate().getLongitude() + (0.01 * deltaLongitude);
mCoordinate.setLatitude(lat);
mCoordinate.setLongitude(lng);
updateMarker();
}
实施如下;
updateMarker