What I want to is display the item just above the line. How do I set item's position for doing that? (as shown in an second image as below)
Asked
Active
Viewed 355 times
2 Answers
1
It seems like currently your marker's center is bound to geopoint, but you want to bound marker's bottom.
So in constructor of your overlay you need to call boundCenterBottom
method like this
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
And may be you need to edit your marker image to place red point at bottom's center to horizontal center of image.
Blue rectangle is approximate size of your image. As you can see marker's center is not in center of the image. Green rectangle is how image should be changed to make marker's center match image's center.

vasart
- 6,692
- 38
- 39
-
Actually it works, there are 3 constructor methods and I have used the code for just one of them. But still there is a problem with fixing for every drawable. For instance some of them look a little left-justified. Is that related to size of the image? If yes what should I do? – Mustafa Güven Dec 07 '12 at 15:01
0
private List<Overlay> mapOverlays;
private Projection projection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
mapOverlays.add(new MyOverlay());
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class MyOverlay extends Overlay{
public MyOverlay(){
}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
GeoPoint gP1 = new GeoPoint(19240000,-99120000);
GeoPoint gP2 = new GeoPoint(37423157, -122085008);
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
}

Talha
- 12,673
- 5
- 49
- 68
-
not related to my problem and also I'm doing all these already. What I want to is moving the item through above. How do I calculate its geopoint for every zoom level? – Mustafa Güven Nov 21 '12 at 09:49