Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
How to find zoom level for a Google Static Map
Google Maps API has an integer "zoom level" which defines the resolution of the current view. Zoom levels between 0 (the lowest zoom level, in which the entire world can be seen on one map) to 21 (down to individual buildings) are possible within the default road maps view. When we want to show several location at the same time in the device screen, we need to find the exact zoom level so we can optimally show the map in the screen. If we want to show several locations in our devices' screen we need to find the zoom level that can be passed Google map static API (for example). If we want to cover entire screen of device that can shows all the interesting points then we can be associated the device screen size with zoom level.
Google Maps sets zoom level 0 to encompass the entire earth. Each succeeding zoom level doubles the precision in both horizontal and vertical dimensions. In this article, we try to find the zoom level of a Google map using Symbian C++ code.
How to calculate zoom level
When the zoom level is 0 then entire world is shown to the device. That means if the device screen is size is 260 pixels then periphery of world should fit to screen width. If we know the distance between two points, we can find the horizontal/vertical component of the distance that should fit to the screen. We need to use the bigger component (between horizontal and vertical) to fit to the device screen.
CosValue = iDistance*cosAngle;
SinValue = iDistance*sinAngle; // Distance between 2 points
valueusedforzoom = (CosValue>SinValue)?CosValue:SinValue;
TReal64 logpartup = (2*KPi* 6372.795)/( valueusedforzoom);
//6372.795 radius of earth in km
TReal64 logpartupval = 0.0;
TInt ret = KErrNone;
ret = Math::Log(logpartupval, logpartup);
TReal64 logpartdownresult = 0.0;
ret = Math::Log(logpartdownresult, 2.0);
TInt zoom = (TInt)(logpartupval/logpartdownresult );
This code can be tested by making a http request to Google server. For example we can make a request with the following http request
where centerLat and centerLon is average latitude and longitude of two places respectively. FoundZoom is the zoom found in the previous code, width and height are the width and height of the device screen. This can be easily verified with this example code How to use Google Maps data in mobile applications.
Here are some images from above http (with addition of markers) request.
Latitude of Tampere = 61.4703;
Longitude of Tampere = 23.7744;
Latitude of Dhaka = 23.7049;
Longitude of Dhaka = 90.4395;
Latitude of Espoo = 60.2043;
Longitude of Espoo = 24.6506;