我创建了显示地图的 android 应用程序。但不幸的是,所有标记显示的位置都略低于其实际位置。我验证了经度和纬度,它们是当前的。
我试过了
marker.setBounds(0, 0, 0 + marker.getIntrinsicWidth(), 0 + marker.getIntrinsicHeight());
这是我的标记加载代码
while (itr.hasNext()) {
Business business = itr.next();
point = new GeoPoint((int)(business.getLatitude() * 1E6),
(int)(business.getLongitude() * 1E6));
List<Overlay> mapOverlays = mMapView.getOverlays();
LinearLayout markerLayout = (LinearLayout)getLayoutInflater().inflate(
R.layout.map_loc_bubble, null);
CustomItem overlayItem = new CustomItem(point, business, markerLayout,
getApplicationContext());
CustomOverlay itemizedOverlay = new CustomOverlay(overlayItem.getDefaultMarker(),this);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
mMapView.invalidate();
}
if (centerPoint != null) {
mMapView.getController().setCenter(centerPoint);
mMapView.getController().animateTo(centerPoint);
}
}
但没有运气
这是我的覆盖类
class CustomOverlay extends ItemizedOverlay<CustomItem> {
public CustomOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomOverlay(Drawable defaultMarker, Context context)
{
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected CustomItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOverlay(CustomItem overlay) {
mOverlays.add(overlay);
populate();
}
public void addOverlay(CustomItem overlay, Drawable marker) {
marker.setBounds(0, 0, 0 + marker.getIntrinsicWidth(), 0 + marker.getIntrinsicHeight());
overlay.setMarker(marker);
addOverlay(overlay);
}
@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, false);
}
}
}