×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to change map zoom level and center point

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - intro text.)
jasfox (Talk | contribs)
m (Jasfox - add monospacing.)
Line 143: Line 143:
 
==Zoom level==
 
==Zoom level==
  
[b]zoomLevel[/b] The map zoom level is defined by this property  
+
{{Icode|zoomLevel}} -  The map zoom level is defined by this property  
 
    
 
    
The zoomLevel is a number between minimum and maximum values and can be queried with minZoomLevel() and maxZoomLevel() methods.  
+
The {{Icode|zoomLevel}} is a number between minimum and maximum values and can be queried with {{Icode|minZoomLevel()}} and {{Icode|maxZoomLevel()}} methods.  
  
 
At the moment, the API offers the scale of zoom between 0 (zero) and 20. This is reflected from the UI component ZoomBar on the Map view. The UI component
 
At the moment, the API offers the scale of zoom between 0 (zero) and 20. This is reflected from the UI component ZoomBar on the Map view. The UI component

Revision as of 17:44, 17 April 2012

This article explains how to change map zoom level and map center.

Article Metadata
Tested with
Devices(s): Internet Explorer, Google Chrome, Firefox, Opera
Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.2.0
Article
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (17 Apr 2012)


Contents

Prerequisites

Nokia Maps API supported web browser (basically any modern web browser)

Important about Maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but you must obtain and use authentication and authorization credentials to use the services. Please read the Location API Business Models and Usage Restrictions page to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials free from the Nokia Developer API Registration page.

Implementation

You can change the parameters for the map view by passing them to your map instance (handled in the article "Add Maps To Any Web Page") that define the zoom level and center point for the map can be set to suite your purposes. The map will default in our example to Berlin, Germany but you can of course change this the center to point to any other location on this planet.

Map center

The map center is defined by the center property and must be provided in type of nokia.maps.geo.Coordinate

Constructor detail:
 
The coordinate represents a geographical position. As most of the use cases currently do not consider height information,
the altitude is defined as optional. If a corresponding type is already provided by the platform the product must not implement this class.
{{Icode| new nokia.maps.geo.Coordinate(lat, lng, [alt, [skipValidation]])}}
 
Parameters:
{Number} lat //Latitude in degrees. -90 <= latitude <= 90. Values outside of range throw an {{Icode| IllegalArgument}} error.
{Number} lng // Longitude in degrees. -180 <= longitude <= 180. Values outside of range throw an {{Icode| IllegalArgument}} error.
{Number} [alt]: undefined // Altitude in meters.
{Boolean} [skipValidation]: false //If being true, then the validation of the latitude, longitude and altitude values is skipped.

We will create a new Coordinate, but will leave out altitude and want the values to be validated, so we will leave the skipValidation to it's default value.


new nokia.maps.geo.Coordinate (lat, lng, [alt, [skipValidation]])

The coordinate represents a geographical position. Altitude is defined as optional. (For more details on this see the Maps API reference).

Note: There is an article about the The coordinate system and geocoordinates. You may want to check it out for more detailed information on the geocoordinate system used in Nokia Maps and some generic information about the world coordinate system.

In our example we will use the latitude and longitude values for the city of Dusseldorf, Germany : 52.51, 13.4. These will be passed in form [52.51, 13.4]. The latitude and longitude can be passed as a floating point number, i.e. 13.4 is just as valid as e.g. 13.456789

ZoomLevel

The Nokia Maps ZoomLevel is a number between minimum and maximum values and can be queried with minZoomLevel() and maxZoomLevel() methods.

At the moment, the API offers the scale of zoom between 0 (zero) and 20. This is reflected from the UI component Zoom Bar on the Map view. The UI component used exact zoom levels respectively are:

Level Name 14 Street 11 City 8 County 3 Country

Example of requesting the min and max zoom levels of the current map:

map.minZoomLevel   // Could return for example "0" (zero)
map.maxZoomLevel // Could return for example "20"

Example code

We are using the same definition as in the example mentioned in the Add Maps To Any Web Page example, just changing the zoomLevel and center

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Map of D&uuml;sseldorf</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.0/jsl.js" charset="utf-8">
</script>
</head>
<body>
<h1>Map of D&uuml;sseldorf</h1>
<div id="map" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("map"),{
'zoomLevel': 8, // Country level
'center': [51.233333, 6.783333] // New map center point
});
</script>
</body>
</html>

When you have defined these, the map should open on Country level of zoom, having the city of Düsseldorf, Germany in the middle of the map view.

Zoom level

zoomLevel - The map zoom level is defined by this property

The zoomLevel is a number between minimum and maximum values and can be queried with minZoomLevel() and maxZoomLevel() methods.

At the moment, the API offers the scale of zoom between 0 (zero) and 20. This is reflected from the UI component ZoomBar on the Map view. The UI component used exact zoom levels respectively are:

Level     Name
14 Street
11 City
8 County
3 Country

Example of requesting the min and max zoom levels of the current map:

map.minZoomLevel   <-  Could return example "0" (zero)
map.maxZoomLevel <- Could return example "20"

For more on Nokia Maps API

Please check out the Nokia Maps API full documentation and API reference here:

You may also access the interactive Nokia Maps API playground,

483 page views in the last 30 days.
×