Computing meter per pixel ratio for current zoom level

8,589 views
Skip to first unread message

Jakub Synowiec

unread,
Jan 5, 2012, 3:58:01 AM1/5/12
to google-map...@googlegroups.com
I'm looking for an equation to compute meter per pixel ratio for given zoom level and latitude. I've found some information considering OSM, but are they relevant to Google Maps? 
Can anyone point me in the right direction?

Marcelo

unread,
Jan 5, 2012, 10:22:45 AM1/5/12
to Google Maps JavaScript API v3
The geometry library can calculate the distance in meters between two
lat/lon pairs.
http://code.google.com/apis/maps/documentation/javascript/geometry.html

The Mercator projection object used in this example:
http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html
allows you to convert lat/lon to pixels.

It may be inportant to understand the concept of World Coordinates:
http://code.google.com/apis/maps/documentation/javascript/maptypes.html#WorldCoordinates

Provided both lat/lon pairs have the same latitude, the pixel distance
is the difference between the two x coordinates.

Finally, divide the mumber meters by the number of pixels to get
meters per pixel.

But I wonder what you want to use this for. If you want to create
something like a measuring tool, you don't need pixels. If you want to
create custom tiles you don't need meters.

--
Marcelo - http://maps.forum.nu
--

Nianwei Liu

unread,
Jan 6, 2012, 6:51:26 AM1/6/12
to Google Maps JavaScript API v3
The info you found for OSM should be applicable to Google Maps as
well.
It's basically find two things: 1) how many horizontal pixel (for
global) at zoom level Z? and 2) how many meters (for global) at
latitude LAT?
The first one is basically 256x2^Z.
The second one should be 2*PI*R*cosine(LATinRadian). R is earth
radius in meters as a sphere.
divide them should get what you need.

If a scale bar is what you are after, I think the API already has a
control for that.

Jakub Synowiec

unread,
Jan 7, 2012, 2:09:47 PM1/7/12
to google-map...@googlegroups.com
I need to draw a polyline that is exactly 200 meters thick, regardless of the zoom level, so I need to compute current scale when map zoom changes or current viewport center changes significantly. But that's a different story.
That "trick" @Marcelo mentioned, about computing distance between two points should work, but I don't like this solution.

If anyone runs into a problem like this, I've attached my function. It should work as supposed.
google.maps.js

Rossko

unread,
Jan 7, 2012, 3:35:22 PM1/7/12
to Google Maps JavaScript API v3
> I need to draw a polyline that is exactly 200 meters thick

I'd have thought it would be easier to draw a polygon of two parallel
sides 200m apart
Reply all
Reply to author
Forward
0 new messages