我创建了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);
}
}
}
答案 0 :(得分:1)
使用Projection将叠加层映射到MapView: 使用它如下
在您的叠加层中,将此代码添加到绘制方法:
Projection projection = mapView.getProjection();
//GeoPoint class is your latitude, longitude.
GeoPoint point = //TODO assign long, lat
//This is your point on the map
Point myPoint = new Point();
projection.toPixels (point, myPoint);
然后你需要某种协调系统来锚定。您可以使用:
// Mark some points through which to draw your circle, or you can do something else
//This just draws circles of radius 5
RectF myShape = new RectF (myPoint.x-5, myPoint.y-5, myPoint.x+5, myPoint.y+5);
canvas.drawOval (mShape, paint);