我正在使用Google Map。我的問題是當我觸摸屏幕mapview不添加引腳完全正確的地方。添加近YCOordinate-50。在mapview中添加pin錯誤的地方?
我也加了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());
}
}
如果u [R採用逐項疊加的話,我覺得你的問題是關係到boundCenterBottom(); –
我更新了我的代碼。它是什麼意思相關的boundCenterBottom()。請幫助我。 – DuyguK