Login     Sign Up
Tugadar (@admin)
14 days ago

The Canvas used to draw Overlay annotations is a standard Canvas that represents the visible display surface. To add annotations based on physical locations, you need to convert between geographical points and screen coordinates.

The Projection class lets you translate between latitude/longitude coordinates (stored as GeoPoints) and x/y screen pixel coordinates (stored as Points).

A map’s Projection may change between subsequent calls to draw, so it’s good practice to get a new instance each time. Get a Map View’s Projection by calling getProjection, as shown in the snippet below:

Projection projection = mapView.getProjection();

Use the fromPixel and toPixel methods to translate from GeoPoints to Points and vice versa.

For performance reasons, the toPixel Projection method is best used by passing a Point object to be populated (rather than relying on the return value), as shown below:

Point myPoint = new Point();

To screen coordinates projection.toPixels(geoPoint, myPoint);

To GeoPoint location coordinates projection.fromPixels(myPoint.x, myPoint.y);