×
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
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
avnee.nathani (Talk | contribs)
(Avnee.nathani - Updated article for Nokia Maps Javascript API v2.0. (Released in Dec 2011))
Line 1: Line 1:
 
[[Category:Web]][[Category:Browser]][[Category:Web]][[Category:Nokia Maps]]
 
[[Category:Web]][[Category:Browser]][[Category:Web]][[Category:Nokia Maps]]
 +
{{Abstract|visible=false|This article explains how to change map zoom level and map center. }}
 +
 +
{{ArticleMetaData
 +
|platform= Web browser
 +
|update-by=[[User:avnee.nathani]]
 +
|update-timestamp=20111231
 +
}}
 
==Introduction==
 
==Introduction==
  
In this article we will introduce the map zoom level and map center.
+
In this article we will introduce the map zoom level and map center for Nokia Maps.
  
 
==Prerequisites==
 
==Prerequisites==
  
Ovi Maps API supported web browser (basically any modern web browser)
+
Nokia Maps API supported web browser (basically any modern web browser)
 
+
The example assumes you have already added the Ovi Maps to your web page as explained in the previous article "Ovi Maps - Add Maps To Any Web Page"
+
  
 
==Important about Maps credentials==
 
==Important about Maps credentials==
  
With Ovi Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the  
+
With Nokia  Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the  
 
offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.  
 
offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.  
 
Note: At the time of writing, it is not necessary to include the token. Please follow the Announcement section for Ovi Maps at Nokia Projects.
 
It will be updated when the authentication is enabled on the backend servers.
 
 
  
 
==Implementation==
 
==Implementation==
  
You can change the parameters for the map view by passing them to your map instance (handled in the article "Ovi Maps - 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 ofcourse change this the center to point to any other location on this planet.
+
You can change the parameters for the map view by passing them to your map instance (handled in the article "Nokia Maps - 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 ofcourse change this the center to point to any other location on this planet.
  
 
==Map center==
 
==Map center==
  
The map center is defined by the center property and must be provided in type of ovi.mapsapi.geo.ICoordinate.
+
The map center is defined by the center property and must be provided in type of nokia.maps.geo.ICoordinate.
  
 
<code java>
 
<code java>
Line 32: Line 33:
 
The coordinate represents a geographical position. As most of the use cases currently do not consider height information,  
 
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.
 
the altitude is defined as optional. If a corresponding type is already provided by the platform the product must not implement this class.
new ovi.mapsapi.geo.Coordinate(lat, lng, [alt, [skipValidation]])
+
new nokia.maps.geo.Coordinate(lat, lng, [alt, [skipValidation]])
  
 
Parameters:
 
Parameters:
Line 46: Line 47:
  
 
<code java>
 
<code java>
new ovi.mapsapi.geo.Coordinate (lat, lng, [alt, [skipValidation]])   
+
new nokia.maps.geo.Coordinate (lat, lng, [alt, [skipValidation]])   
 
</code>
 
</code>
  
 
The coordinate represents a geographical position. Altitude is defined as optional. (For more details on this see the Maps API reference).
 
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 coordinate system and geocoordinates titled: "Ovi Maps API - Geocoordinates". You may want to check it out for more detailed information on the geocoordinate system used in Ovi Maps and some generic information about the world coordinate system.
+
Note: There is an article about the coordinate system and geocoordinates titled: "Nokia Maps API - 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].  
 
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].  
Line 58: Line 59:
 
==ZoomLevel==
 
==ZoomLevel==
  
The Ovi Maps ZoomLevel is a number between minimum and maximum values and can be queried with minZoomLevel() and maxZoomLevel() methods.  
+
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 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
Line 92: Line 93:
  
 
When you have defined these, the map should open on Country level of zoom, having the city of Dusseldorf, Germany in the middle of the map view.
 
When you have defined these, the map should open on Country level of zoom, having the city of Dusseldorf, Germany in the middle of the map view.
 
 
==For more on Ovi Maps API==
 
 
Please check out the Ovi Maps API full documentation and API reference here:
 
 
[link]http://api.maps.ovi.com[/link]
 
 
 
==Zoom level==
 
==Zoom level==
  
Line 127: Line 120:
 
==Example code==
 
==Example code==
  
This code will add the zoomLevel and center point. Please visit the article "Ovi Maps API - Add Maps To Any Page", there the Example code
+
This code will add the zoomLevel and center point. Please visit the article "Nokia Maps API - Add Maps To Any Page", there the Example code
 
is divided in two: Example 1 and 2. The code below is what is added to the Example 1, thus making the map to position itself somewhere else than the coordinate 0,0 as is by default and setting the zoom level to be > 0. The default zoom level if not specified, is zero (0).
 
is divided in two: Example 1 and 2. The code below is what is added to the Example 1, thus making the map to position itself somewhere else than the coordinate 0,0 as is by default and setting the zoom level to be > 0. The default zoom level if not specified, is zero (0).
  
Line 143: Line 136:
  
  
==For more on Ovi Maps API==
+
==For more on Nokia Maps API==
  
Please check out the Ovi Maps API full documentation and API reference here:
+
Please check out the Nokia Maps API full documentation and API reference here:
 +
* http://api.maps.nokia.com/2.0.0
  
http://api.maps.ovi.com
+
You may also access the interactive Nokia Maps API playground,
 +
* http://api.maps.nokia.com/playground/index.html
  
 
==Tested on==
 
==Tested on==
  
Google Chrome 11.0x
+
* Google Chrome 11.0x
 
+
* Mozilla Firefox 5.0
Mozilla Firefox 5.0
+

Revision as of 12:52, 31 December 2011


Article Metadata
Compatibility
Platform(s): Web browser
Article
Created: (31 Dec 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: avnee.nathani (31 Dec 2011)

Contents

Introduction

In this article we will introduce the map zoom level and map center for Nokia Maps.

Prerequisites

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

Important about Maps credentials

With Nokia Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.

Implementation

You can change the parameters for the map view by passing them to your map instance (handled in the article "Nokia Maps - 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 ofcourse 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.ICoordinate.

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.
new nokia.maps.geo.Coordinate(lat, lng, [alt, [skipValidation]])
 
Parameters:
{Number} lat //Latitude in degrees. -90 <= latitude <= 90. Values outside of range throw IllegalArgument error.
{Number} lng // Longitude in degrees. -180 <= longitude <= 180. Values outside of range throw 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 coordinate system and geocoordinates titled: "Nokia Maps API - 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 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 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 section "Prerequisites".


...                                                    
{
'zoomLevel': 8, // Country level
'center': [52.51, 13.4] // New map center point
}
);
...

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

Zoom level

[b]zoomLevel[/b] 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"


Example code

This code will add the zoomLevel and center point. Please visit the article "Nokia Maps API - Add Maps To Any Page", there the Example code is divided in two: Example 1 and 2. The code below is what is added to the Example 1, thus making the map to position itself somewhere else than the coordinate 0,0 as is by default and setting the zoom level to be > 0. The default zoom level if not specified, is zero (0).

...                                                    
{
'zoomLevel': 8, // Country level
'center': [52.51, 13.4] // New map center point
}
);
...

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


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,

Tested on

  • Google Chrome 11.0x
  • Mozilla Firefox 5.0
567 page views in the last 30 days.
×