[英]android here sdk moving markers
I need to be able to show moving cars using Here maps android sdk. 我需要能够使用Here Maps Android SDK显示动车。 Is it possible in the current version?
当前版本有可能吗? I tried to remove and add map marker object in a render like loop logic as the following;
我试图在渲染(如循环逻辑)中删除和添加地图标记对象,如下所示;
// 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);
}
The removeMapObject()
doesn't seem to be working. removeMapObject()
似乎不起作用。 Any ideas to have a moving map object ? 有什么想法可以移动地图对象吗?
The problem here was to create each marker and remove them and re-add them. 这里的问题是创建每个标记并将其删除并重新添加。 The render loop would be the following;
渲染循环如下:
// 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);
}
The addDelta()
call should update the marker coordinate and its own coordinate; 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();
}
And lastly, updateMarker
implementation is the following; 最后,
updateMarker
实现如下:
public void updateMarker() {
mMarker = new MapMarker();
Image image = new Image();
image.setBitmap(mIcon.toBitmap());
mMarker.setCoordinate(mCoordinate);
mMarker.setIcon(image);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.