# How to calculate pixels per meter ratio, according to Google or Bing map zoom level?

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.

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;
}
``````

There are two really good articles in the Bing Maps documentation around the tiling system and scale/resolution:

http://msdn.microsoft.com/en-us/library/aa940990.aspx

Assuming you have or can get the latitude and longitude of the center of the map, or the center of the ship for more accuracy, you can then calculate the ground resolution in meters/pixel for that level of latitude. At zoom level 19, a single pixel is approximately 30cm in size, or 1 foot, at the equator. The formula for this is:

``````ground_resolution = (cos(Latitude * pi/180) * 2 * pi * 6378137) / (256 * 2 ^ zoomLevel)
``````

Once you have this, you can get approximate distances by converting your pixel distances to meters.

• So, what units is this `ground_resolution` in? `m/pixel`? Then to get the left side of my image in meters, I would use `mercator(center.lat) - (image.width / 2) * ground_resolution`? Where `mercator(n:number):number` crudely is `return 6378137 * n * Math.PI/180;` – WebWanderer Sep 19 '18 at 17:35