-
Notifications
You must be signed in to change notification settings - Fork 75
Map calculations
mtehver edited this page Dec 28, 2013
·
3 revisions
- From screen coordinates to geo coordinates (in layer projection):
MapPos worldPos = mapView.screenToWorld(screenX, screenY);
- From geo coordinates (in layer projection) to screen:
MapPos screenPos = mapView.worldToScreen(mapX, mapY);
- 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];
}