Cyrille Telmer
Cyrille Telmer

Reputation: 123

Set the marker center to the GeoPoint

I'm working on osmdroid, and trying to do something very simple, that i used to do on another map framework, but i can't find how to do it on OSMdroid. I want to put a marker somewhere on the map, on a GeoPoint. Up to this, it's easy. But i also want the center of the marker pic to be on the susmentioned geopoint. With my code, right now, the geopoint is at the left bottom corner of the image.

How to do that?

Upvotes: 3

Views: 3520

Answers (3)

Vitaly
Vitaly

Reputation: 437

If you are using Marker class, then better to use code below...

Marker marker = new Marker(map);
marker.setAnchor((float)0.5, (float)0.5); // center icon to geo pint

Upvotes: 2

Cyrille Telmer
Cyrille Telmer

Reputation: 123

OK, I found it. So I'm answering my question in case somebody has the same problem.

I tried first your idea woodstock, but i failed to find a boundCenter Method.

So in order to make the GeoPoint the center of the drawable, you just need to do that:

overlayItem.setMarker(YourDrawable);
overlayItem.setMarkerHotspot(HotspotPlace.CENTER);

Upvotes: 9

woodstock365
woodstock365

Reputation: 1800

I haven't used osmdroid before, but you can normally achieve this by setting the bounds of the marker.

For example, when using Google's MapView you would use the following code to specify that you want the center of the marker to be on the given GeoPoint:

super(boundCenter(defaultMarker));

Upvotes: 0

Related Questions