开发者

Fetch map center when i scroll through the map in android

开发者 https://www.devze.com 2023-02-13 02:55 出处:网络
I have a mapview in my app. My requirement开发者_如何学编程 is each time when I scroll through the map, I have to fetch the current center point of the map. How can I achieve it?Documentation

I have a mapview in my app. My requirement开发者_如何学编程 is each time when I scroll through the map, I have to fetch the current center point of the map. How can I achieve it?


Documentation

getMapCenter()


First get a projection for converting between screen-pixel coordinates and latitude/longitude coordinates.

Projection P = mapview.getProjection();

Now you need to find the height and width of the screen in pixels and divide each by two which will given you the pixel coordinates of the center of the screen.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

GeoPoint G = P.fromPixels(metrics.heightPixels/2, metrics.widthPixels/2);

G is the GeoPoint of the center of your present screen.

0

精彩评论

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