##### Actions

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

# How to find zoom level for a Google Static Map

Article
Created: mahbub_s60 (19 Apr 2010)
Last edited: hamishwillee (26 Jan 2012)

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.

`User::LeaveIfError(Math::Cos(cosAngle, iAngleWithHorizontal));CosValue = iDistance*cosAngle;User::LeaveIfError(Math::Sin(sinAngle, iAngleWithHorizontal));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);	 	 User::LeaveIfError(ret); TReal64 logpartdownresult = 0.0;ret = Math::Log(logpartdownresult, 2.0);	 	 User::LeaveIfError(ret);	 TInt zoom = (TInt)(logpartupval/logpartdownresult );`

## Code example

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

```http://maps.googleapis.com/maps/api/staticmap?center=centerLat,centerLon&zoom=FoundZoom&size=widthxheight&sensor=false
```

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.

## Test result

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;

```
```