Reputation: 125
I have created android app where i show map. But unfortunately all the markers shows little lower than its actual position. I verified longitude and latitude and they are current ones.
I tried with
marker.setBounds(0, 0, 0 + marker.getIntrinsicWidth(), 0 + marker.getIntrinsicHeight());
this is my markers loading code
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);
}
}
but no luck
here is my overlay class
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);
}
}
}
Upvotes: 0
Views: 505
Reputation: 4222
Use Projection to map your Overlay to your MapView: use it like follows
In your Overlay, Add this code to draw method:
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);
Then you need some sort of a co-ordinate system to anchor. You can use:
// 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);
Upvotes: 1