本文介绍了移动标记在谷歌地图V2的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做图的聚类在Android的谷歌地图V2。我只是想标记动画从一个GeoPoint对象到另一个。有没有一种方法来移动标记在谷歌地图V2?
I am doing map clustering in Android Google maps v2.I just want to animate the marker from one geopoint to another. Is there a way to move a marker in Google maps v2?
推荐答案
有移动的标志在谷歌地图V2演示程序..玩库的样品中的一个例子!
There's one example of moving marker in google map v2 demo app .. in the sample of the play library!!
我已经研究过了!这里code移动的标记: - >
I have looked into that!! here the code for moving an marker : -- >
public void animateMarker(final Marker marker, final LatLng toPosition,
final boolean hideMarker) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = mGoogleMapObject.getProjection();
Point startPoint = proj.toScreenLocation(marker.getPosition());
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
final long duration = 500;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * toPosition.longitude + (1 - t)
* startLatLng.longitude;
double lat = t * toPosition.latitude + (1 - t)
* startLatLng.latitude;
marker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}
希望它可以帮助每一个人!
Hope it help every one!!
这篇关于移动标记在谷歌地图V2的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!