我正在使用谷歌地图V2 for Android,我正在尝试创建一种方法来获取像素的大小,以计算像素缩放级别。这是我的代码:
private int calculateZoomLevel() {
int ht, screenWidth;
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
ht = displayMetrics.heightPixels;
screenWidth = displayMetrics.widthPixels;
double equatorLength = 40075004;
double widthInPixels = screenWidth;
double metersPerPixel = equatorLength / 256;
int zoomLevel = 1;
while ((metersPerPixel * widthInPixels) > 1000) {
metersPerPixel /= 2;
++zoomLevel;
}
Log.i(TAG, "zoom level is: "+ zoomLevel);
return zoomLevel;
}
public float metersToEquatorPixels(final float meters) {
return meters / EQUATORCIRCUMFENCE * getWorldSizePx();
}
int getWorldSizePx() {
return 1 << getPixelZoomLevel();
}
int getPixelZoomLevel() {
return calculateZoomLevel() + getMapTileZoom(mTileSizePixels);
}
public static int getMapTileZoom(final int tileSizePixels) {
if (tileSizePixels <= 0) {
return 0;
}
int pixels = tileSizePixels;
int a = 0;
while (pixels != 0) {
pixels >>= 1;
a++;
}
return a - 1;
}
我在GMaps V2文档中看到,您可以使用Tile类来获取Tile的宽度和高度,但我不知道如何获取data []参数的tile数据。我在这里走在正确的轨道上吗?
任何建议都将不胜感激。