开发者

How can I get the distance in pixels between two points on the map, before/during zoom?

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 = /开发者_StackOverflow中文版/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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜