如何从规模像素米MapView类 [英] How to scale a MapView from Pixels to Meters

查看:99
本文介绍了如何从规模像素米MapView类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做它使用谷歌地图API的Andr​​oid应用程序,我想缩放MapView类来X_pixels:X_meters

I'm making an Android application which uses Google Maps API, and I want to scale a MapView to X_pixels:X_meters.

例如,5像素的MapView在我的屏幕20米的现实。

For example, 5 pixels of the MapView in my screen, 20 meters on reality.

这可能吗?

THX

推荐答案

使用以下code:

    int nPixles = 5; //number of pixels
    GeoPoint g0 = mapview.getProjection().fromPixels(0, mapview.getHeight()/2);
    GeoPoint g1 = mapview.getProjection().fromPixels(nPixles, mapview.getHeight()/2);
    float[] results = new float[1];
    Location.distanceBetween(g0.getLatitudeE6()/1E6, g0.getLongitudeE6()/1E6, g1.getLatitudeE6(), g1.getLongitudeE6()/1E6, results);
    float distanceInMeters = results[0];

此计算在屏幕中心纬度水平米的距离。因为地球是球形的距离从底部变化到屏幕的顶部。这主要是发现低缩放级别。

This calculates distance in meters for latitude level at screen center. Because earth is spheric distance vary from bottom to the top of screen. This is mostly noticed with low zoom levels.

问候。

这篇关于如何从规模像素米MapView类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆