Skip to content
Nutiteq edited this page Aug 8, 2014 · 3 revisions
  1. From screen coordinates to geo coordinates (in base layer projection):
  MapPos worldPos = mapView.screenToWorld(screenX, screenY);
  1. From geo coordinates (in base layer projection) to screen:
  MapPos screenPos = mapView.worldToScreen(mapX, mapY);
  1. Calculate width of map view in meters, using Android Location package:
private float getMapViewWidth(MapView mapView){
        MapPos bottomLeft = mapView.screenToWorld(0, mapView.getHeight());
        MapPos bottomRight = mapView.screenToWorld(mapView.getWidth(), mapView.getHeight());
        
        float[] results = new float[3];
        
        Location.distanceBetween(this.proj.toWgs84(bottomLeft.x,bottomLeft.y).x,
                this.proj.toWgs84(bottomLeft.x,bottomLeft.y).y,
                this.proj.toWgs84(bottomRight.x,bottomRight.y).x,
                this.proj.toWgs84(bottomRight.x,bottomRight.y).y, results);
        
        return results[0];
}
Clone this wiki locally