We need a Map.getScale() method

15604 views
Skip to first unread message

louis-rémi Babé

unread,
Aug 25, 2011, 6:55:55 AM8/25/11
to google-map...@googlegroups.com
Hi,

It is currently possible to display a scale control, but there is no way to access the scale value from code.

I'd like a a .getScale() method to be added to Map objects in the next version of the API.
It should return meters/pixel and feets/pixel values for the current zoom level.

Regards,
loui...@mozilla.com

Joseph Elfelt

unread,
Aug 25, 2011, 8:32:51 AM8/25/11
to Google Maps JavaScript API v3
Someone worked out the following values.

// An array holds values for meters_per_pixel based on the zoom
level
masu.meters_per_pixel_ary = [];
masu.meters_per_pixel_ary[0] = 156543.03392;
masu.meters_per_pixel_ary[1] = 78271.51696;
masu.meters_per_pixel_ary[2] = 39135.75848;
masu.meters_per_pixel_ary[3] = 19567.87924;
masu.meters_per_pixel_ary[4] = 9783.93962;
masu.meters_per_pixel_ary[5] = 4891.96981;
masu.meters_per_pixel_ary[6] = 2445.98490;
masu.meters_per_pixel_ary[7] = 1222.99245;
masu.meters_per_pixel_ary[8] = 611.49622;
masu.meters_per_pixel_ary[9] = 305.74811;
masu.meters_per_pixel_ary[10] = 152.87405;
masu.meters_per_pixel_ary[11] = 76.43702;
masu.meters_per_pixel_ary[12] = 38.21851;
masu.meters_per_pixel_ary[13] = 19.10925;
masu.meters_per_pixel_ary[14] = 9.55462;
masu.meters_per_pixel_ary[15] = 4.77731;
masu.meters_per_pixel_ary[16] = 2.38865;
masu.meters_per_pixel_ary[17] = 1.19432;
masu.meters_per_pixel_ary[18] = 0.59716;
masu.meters_per_pixel_ary[19] = 0.29858;

Chris Broadfoot

unread,
Aug 25, 2011, 8:44:26 AM8/25/11
to google-map...@googlegroups.com
This won't be accurate, because the resolution of a map with the mercator projection (like Google maps) is dependent on the latitude.

It's possible to calculate using this formula:

156543.03392 * Math.cos(latLng.lat() * Math.PI / 180) / Math.pow(2, zoom)

This is based on the assumption that the earth's radius is 6378137m. Which is the value we use :)


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Joseph Elfelt

unread,
Aug 25, 2011, 9:44:35 AM8/25/11
to Google Maps JavaScript API v3
Chris,

Thanks for the correction and info.

Totardo Tobing

unread,
Feb 22, 2016, 5:41:53 PM2/22/16
to Google Maps JavaScript API v3
Hi, anyone one how many Kilometer 1 px does? My calculation is 1Px = 11.627 Km at maximum zoom. But this is not correct

Homing Tam

unread,
Sep 18, 2016, 11:01:12 PM9/18/16
to Google Maps JavaScript API v3
hi, which scale are you referring to for "maximum zoom"?

Please consider the environment before printing this email or attachment

This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Master Concept Group and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic.

Andrew Leach

unread,
Sep 19, 2016, 5:24:07 AM9/19/16
to Google Maps JavaScript API v3
On Monday, 22 February 2016 22:41:53 UTC, Totardo Tobing wrote:
Hi, anyone one how many Kilometer 1 px does? My calculation is 1Px = 11.627 Km at maximum zoom. But this is not correct


If you look at the Group posts in this topic at https://groups.google.com/forum/#!topic/google-maps-js-api-v3/hDRO4oHVSeM, there is a formula for calculating it based on latitude. Mercator projection produces a different horizontal scale at different latitudes, and another different vertical scale.

Reply all
Reply to author
Forward
0 new messages