15,797,822 members
See more:
Hello
am use google static maps in my windows form app
when i get the map i set the center point "latitude,longitude" , zoom and image size
the boundaries coordinates calculated by this code
C#
```double scale = Math.Pow(2, m_intZoom);
NW_Latitude = CenterLat + (PicSizeY / 2) / scale;
NW_Longitude = CenterLon - (PicSizeX / 2) / scale;
NE_Longitude = CenterLon + (PicSizeX / 2) / scale;
WS_Latitude = CenterLat - (PicSizeY / 2) / scale;
```

Now
i found a way to calculate the distance between two coords
C#
```double earthR = 6371;

double deltaLat = 0;

double deltaLon = (m_dblLocationNWLongitude - m_dblLocationNELongitude) * Math.PI / 180;

double a = Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2) +
Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) * Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
Math.Sin(deltaLon / 2) * Math.Sin(deltaLon / 2);
double b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

MapWidthDistance = earthR * b;
///////////////////////////
deltaLat = (m_dblLocationNWLatitude - m_dblLocationWSLatitude) * Math.PI / 180;

deltaLon = 0;

a = Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2) +
Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
Math.Cos(m_dblLocationNWLatitude * Math.PI / 180) *
Math.Sin(deltaLon / 2) * Math.Sin(deltaLon / 2);

b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

MapHeightDistance = earthR * b;```

but i think there is something wrong because when i set the image size to 600x600
and calculate the distance i got MapWidthDistance != MapHeightDistance
note that the area covered in map is small and defined as a square

Any Suggestions or Solutions?
Posted
Updated 12-Dec-14 22:07pm
v3

## Solution 1

I calculate it by using the center point
C#
```double earthC = 6371000 * 2 * Math.PI;
double factor = Math.Pow(2, 8 + m_intZoomLevel);
double MeterPerPixel = (Math.Cos(CenterLat * Math.PI / 180) * earthC / factor)/2;
double MapWidthDistance = OrginalImageWidth * MeterPerPixel;
double ActualMeterPerPixel = MapWidthDistance / imgWidthAfterResize;```