gpt4 book ai didi

android - 如何使用谷歌地图在android中实现Drop pin动画?

转载 作者:太空宇宙 更新时间:2023-11-03 13:04:15 25 4
gpt4 key购买 nike

我想像在 iPhone 中那样为标记实现放置图钉动画。问题是别针没有像他们在这个链接中那样按照他们应该的方式掉落: http://googlegeodevelopers.blogspot.com/2010/12/map-markers-they-move.html .我已经添加了示例代码。 请帮助实现动画。

public class MyMapAnimation extends MapActivity {
private MapView map = null;
private MyLocationOverlay me = null;
ImageView imageView = null;
Projection proj = null;
private Drawable marker;
private ArrayList<OverlayItem> itemsArrayList;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("NooYawk","onCreate");

itemsArrayList = new ArrayList<OverlayItem>();
itemsArrayList.add(new OverlayItem(getPoint(40.748963847316034,
-73.96807193756104), "UN", "United Nations"));
itemsArrayList.add(new OverlayItem(getPoint(40.76866299974387,
-73.98268461227417), "Lincoln Center",
"Home of Jazz at Lincoln Center"));

itemsArrayList.add(new OverlayItem(getPoint(40.765136435316755,
-73.97989511489868), "Carnegie Hall",
"Where you go with practice, practice, practice"));
itemsArrayList.add(new OverlayItem(getPoint(40.70686417491799,
-74.01572942733765), "The Downtown Club",
"Original home of the Heisman Trophy"));

map = (MapView) findViewById(R.id.map);


map.getController().setCenter(getPoint(40.748963847316034,
-73.96807193756104));
/* map.getController().setCenter(
getPoint(40.748963847316034, -73.96807193756104));*/
map.getController().setZoom(12);
map.setBuiltInZoomControls(true);

marker = getResources().getDrawable(R.drawable.marker);

proj = map.getProjection();
imageView = new ImageView(this);

imageView.setBackgroundResource(R.drawable.marker);

marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());


map.getOverlays().add(new SitesOverlay(marker));

me = new MyLocationOverlay(this, map);
map.getOverlays().add(me);

/*
* map.getController().animateTo( getPoint(40.748963847316034,
* -73.96807193756104));
*/

}

@Override
public void onResume() {
super.onResume();
me.enableCompass();
Log.i("NooYawk","onResume");
}

@Override
public void onPause() {
super.onPause();
Log.i("NooYawk","onPause");
me.disableCompass();
}

@Override
protected boolean isRouteDisplayed() {
Log.i("NooYawk","isRouteDisplayed");
return (false);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_S) {
map.setSatellite(!map.isSatellite());
return (true);
} else if (keyCode == KeyEvent.KEYCODE_Z) {
map.displayZoomControls(true);
return (true);
}

return (super.onKeyDown(keyCode, event));
}

private GeoPoint getPoint(double lat, double lon) {
Log.i("NooYawk","getPoint");
return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
}

private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items = new ArrayList<OverlayItem>();
private Drawable marker = null;
private OverlayItem inDrag = null;
private ImageView dragImage = null;
private int xDragImageOffset = 0;
private int yDragImageOffset = 0;
private int xDragTouchOffset = 0;
private int yDragTouchOffset = 0;
Point p = new Point(0, 0);
private RelativeLayout relativeLayout;
private ArrayList<ImageView> imageViewArrayList;

public SitesOverlay(Drawable marker) {
super(marker);
this.marker = marker;



Log.i("NooYawk","SitesOverlay");
dragImage = (ImageView) findViewById(R.id.drag);



Log.d("POint",
""
+ (map.getProjection().toPixels(
getPoint(40.748963847316034,
-73.96807193756104), p).x)
+ ","
+ (map.getProjection().toPixels(
getPoint(40.748963847316034,
-73.96807193756104), p).y));

TranslateAnimation translateAnimation = null;

imageViewArrayList = new ArrayList<ImageView>();
for (OverlayItem currentOverlayItem : itemsArrayList) {
Log.i("NooYawk","currentOverlayItem");
imageView = new ImageView(NooYawk.this);

imageView.setBackgroundResource(R.drawable.marker);

relativeLayout = (RelativeLayout) findViewById(R.id.rl_map_main);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
param.leftMargin = getWindowManager().getDefaultDisplay()
.getWidth() / 2;
param.topMargin = 0;

relativeLayout.addView(imageView, param);
imageViewArrayList.add(imageView);
}
int count = 0;
Log.i("x for translate before animation",
(map.getProjection().toPixels(
itemsArrayList.get(0).getPoint(), p).x)+"");
for (ImageView currentImageView : imageViewArrayList) {
Log.i("NooYawk","currentImageView");
translateAnimation = new TranslateAnimation((map
.getProjection().toPixels(
itemsArrayList.get(count).getPoint(), p).x),
(map.getProjection().toPixels(
itemsArrayList.get(count).getPoint(), p).x), 0,
(map.getProjection().toPixels(
itemsArrayList.get(count).getPoint(), p).y));


translateAnimation.setDuration(2000);
currentImageView.startAnimation(translateAnimation);
count++;
}

new Handler().postDelayed(new Runnable() {


@Override
public void run() {
Log.i("NooYawk","run");
// relativeLayout.removeView(imageView);
for (ImageView currentImageView : imageViewArrayList) {
Log.i("NooYawk","thread : currentImageView");
currentImageView.setVisibility(View.INVISIBLE);
}
setItemValues();
populate();

Log.i("x for translate after animation",
(map.getProjection().toPixels(
itemsArrayList.get(0).getPoint(), p).x)+"");
}
}, translateAnimation.getDuration());

}

private void setItemValues() {
int count = 0;
Log.i("NooYawk","setItemVAlues");
for (OverlayItem currentOverlayItem : itemsArrayList) {
items.add(currentOverlayItem);

Log.i("items ", items.get(count).getPoint()+"");
count++;
}
}

@Override
protected OverlayItem createItem(int i) {
Log.i("NooYawk","createitem");
return (items.get(i));
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
// items.get(0)
Log.i("NooYawk","draw");
boundCenterBottom(marker);

}

@Override
public int size() {
Log.i("NooYawk","size");
return (items.size());
}

}

最佳答案

我正在发布的核心概念是使 mapView 中的下拉图钉动画与 iPhopne 的一样。同样可以与叠加层集成......

Drawable drawableImage = this.getResources().getDrawable(R.drawable.marker);
myCustomOverlay = new CustomOverlay(drawableImage, mapView);
initGeoPoint = new GeoPoint((int) (latitudeArray[i] * 1E6),(int) (longitudeArray[i] * 1E6));
OverlayItem overlayItem = new OverlayItem(initGeoPoint,getLocationAddress(latitudeArray[i], longitudeArray[i]),"xyz");

myCustomOverlay.addOverlay(overlayItem);
mapOverlays.add(myCustomOverlay);

RelativeLayout v = (RelativeLayout) View.inflate(getApplicationContext(),R.layout.marker_layout, null);
ImageView markerView = (ImageView) v.findViewById(R.id.marker_img_view);
AnimationSet animation = new AnimationSet(true);

TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f, -400.0f, 0.0f);
translateAnimation.setDuration(1000);
animation.addAnimation(translateAnimation);

markerView.startAnimation(animation);

mapView.addView(v,
new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT),
new GeoPoint((int) (latitude * 1E6),(int) (longitude * 1E6)),
MapView.LayoutParams.BOTTOM_CENTER));

mapView.invalidate();

marker_layout 如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
android:id="@+id/marker_img_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/marker" />

</RelativeLayout>

覆盖类###########

public class CustomOverlay extends BalloonItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;

public CustomOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}

public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if (!shadow) {
super.draw(canvas, mapView, false);
}
}

public void removeOverlay(OverlayItem overlay) {
m_overlays.remove(overlay);
populate();
}

@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}

@Override
public int size() {
return m_overlays.size();
}

@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
Toast.makeText(
c,
"onBalloonTap for overlay index " + index + " Item"
+ item.getTitle(), Toast.LENGTH_LONG).show();

String id = "";

return true;
}
}

关于android - 如何使用谷歌地图在android中实现Drop pin动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com