-
Notifications
You must be signed in to change notification settings - Fork 75
Map calculations
Nutiteq edited this page Aug 8, 2014
·
3 revisions
- From screen coordinates to geo coordinates (in base layer projection):
MapPos worldPos = mapView.screenToWorld(screenX, screenY);
- From geo coordinates (in base 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];
}