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.

2 Answers 2


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:



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; Commented Sep 19, 2018 at 17:35
  • I saw several formulas of the kind and still can't imagine why meter-per-pixel ratio depends on latitude. I believe maps are not Mercator projection, and on the poles there are same meters in pixel as on the equator, isn't it?
    – tequilacat
    Commented Jul 21, 2020 at 15:04
  • 1
    The maps use Mercator projection which is needed to make a flat/square map. This projection needs to stretch the pixels near the poles. Here is a simple demonstration of the Mercator projection: youtube.com/watch?v=CPQZ7NcQ6YQ
    – rbrundritt
    Commented Jul 22, 2020 at 16:15
  • Thanks. I know what the Mercator projection is, I just though the web maps use globe-like projection without any stretching.
    – tequilacat
    Commented Jul 22, 2020 at 22:34
  • Most of their maps use Mercator. Although they may have one or two map controls that have globe like projections
    – rbrundritt
    Commented Jul 24, 2020 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.