【发布时间】:2012-01-16 14:39:02
【问题描述】:
我正在使用谷歌地图。我的问题是当我触摸屏幕时,mapview 没有在正确的位置添加 pin。添加接近 Ycoordinate-50。
我也添加了 CustomitemzedOverlay。
代码有什么问题?
谁能帮帮我?
代码:
public void AddPoint(Drawable drawable, MapView mapView, MotionEvent motionEvent) {
p = mapView.getProjection().fromPixels((int) (motionEvent.getX()),(int) (motionEvent.getY()));
final MapController mc = mapView.getController();
mc.setZoom(16);
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
itemizedOverlay.addOverlay(new CustomOverlayItem(p,"","",""));
mapView.getOverlays().add(itemizedOverlay);
mc.animateTo(p);
mapView.invalidate();
}
package com.example;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import java.util.ArrayList;
public class CustomItemizedOverlay<Item extends OverlayItem> extends BalloonItemizedOverlay<CustomOverlayItem> {
private ArrayList<CustomOverlayItem> m_overlays = new ArrayList<CustomOverlayItem>();
private Context c;
public CustomItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
public void addOverlay(CustomOverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
public void removeOverlay(CustomOverlayItem overlay) {
m_overlays.remove(overlay);
populate();
}
@Override
protected CustomOverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index, CustomOverlayItem item) {
Toast.makeText(c, "onBalloonTap for overlay index " + index,
Toast.LENGTH_LONG).show();
return true;
}
@Override
protected BalloonOverlayView<CustomOverlayItem> createBalloonOverlayView() {
// use our custom balloon view with our custom overlay item type:
return new CustomBalloonOverlayView<CustomOverlayItem>(getMapView().getContext(), getBalloonBottomOffset());
}
}
【问题讨论】:
-
如果您使用逐项叠加,那么我认为您的问题与 boundCenterBottom();
-
我更新了我的代码。boundCenterBottom()相关是什么意思。请帮帮我。