3

I need to calculate what the distance in pixels between two points on a map will be after a zoom event. My problem is that the projection gives inconsistent results while the map is zooming.

The calculation is simple:

Projection p = mapView.getProjection();
Point p1 = new Point();
Point p2 = new Point();
GeoPoint g1 = //value1
GeoPoint g2 = //value2
p.toPixels(g1, p1);
p.toPixels(g2, p2);
double distancePx = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));

I detect a zoom in my dispatchDraw method of my MapView. If I do the calculation right then I get inconsistent and weird results. If I wait half a second and try that calculation, I get perfect results. That's a little late though, as I really need to know the answer before I finish zooming. Ideally I'd be able to figure out the distance in pixels based solely on the zoomLevel. Any ideas?

Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
  • Hrm can you scale your distance according to the zoom level? So if your at 150% zoom, scale your distancePx by that much? – Jack Aug 11 '11 at 14:45
  • I figured it wouldn't be, but it was worth a try :) – Jack Aug 11 '11 at 15:11

0 Answers0