[GIS] How to calculate pixels per meter ratio, according to Google or Bing map zoom level

bing-mapsdistancegoogle mapsresolutionscale

I have an image and detect two points in the image. I want to calculate the distance between these two points. I'm using Google map and Bing map.

I have

  • x,y pixel values for both two points
  • zoom level 19, or something else

What I need is the pixels per meter ratio.

Best Answer

I have written this on Android and it works. Google map tiles are 256 device independent pixels. So this first line calculates a tile size in device dependent pixels. The second calculates the number of tiles at a given zoom level. The third calculates the size of a tile in meters at a given latitude for spherical projection. Then the final line will give you pixels per meter. This could be optimized a bit, but it should make sense.

public double getPixelsPerMeter(double lat, double zoom) {
    double pixelsPerTile = 256 * ((double)context.getResources().getDisplayMetrics().densityDpi / 160);
    double numTiles = Math.pow(2,zoom);
    double metersPerTile = Math.cos(Math.toRadians(lat)) * EARTH_CIRCUMFERENCE_METERS / numTiles;
    return pixelsPerTile / metersPerTile;
}