Revision as of 13:42, 21 June 2011 by Maveric (Talk | contribs)

HERE Maps API - How to add map markers

From Nokia Developer Wiki
Jump to: navigation, search



In this article we will go thru on how to add one or more Markers to the map. A marker defines an Object that may display an icon on the map view.


A 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 the map to any web page"

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 offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.

For more information on how to obtain the credentials, please start with the Ovi Maps API Developers Guide section "Acquiring API credentials"


First we will need to define the Marker. This will be done by specifying:

    myMarker = new ovi.mapsapi.map.Marker([50.1,13.1]);

The Marker needs geocoordinates as parameters, that is, the latitude and longitude it will be placed on the map. In our example we are using 50.1 for the latitude and 13.1 for the longitude. myMarker now contains a new Marker object.

To be able to put the Marker on the map, we will need to introduce a new Container. A Container is used to group Objects, thus allowing it to operate on a whole group of objects without the need to iteratively visit each Object (i.e., for changing the visibility).

    var myContainer = new ovi.mapsapi.map.Container()

Now that we have the Container ready, we can add the Marker into it:

//or another way of putting this e.g. myContainer.objects.add(new ovi.mapsapi.map.StandardMarker([52.45705,13.21173]));

And then when the Marker is in the Container, we will need to add the Container to the map objects collection, to be able to show the content on it:


The properties of the Marker can be further manipulated, e.g. you can make the Marker draggable (it is not that by default) if you wish:


And to make the Marker static again, you would give:


For a marker you can set a text e.g.

    myMarker.set("text","Your marker!")

An external image can be attached as follows:


Or you can select from the predefined list of shapes:

    var use_this_shape = "star";
myMarker.set("shape", use_this_shape);
Sometimes it may be useful to know if a Container has been added to the Display. Earlier we could have initiated the Display object e.g. like this:
var map = new ovi.mapsapi.map.Display(document.getElementById("map"),

Now, with the reference to “map”, we can request:

    test = myMarkerContainer.isAdded (map)

In our case test would result in “true”.

With the isVisible (display) : Boolean we will get true if the object's visibility as well as all parent's visibilities are true and if the object is attached to a map (i.e. parent chain ends with a map). The returned value is only valid for the given ovi.mapsapi.map.Display object.


{ovi.mapsapi.map.Display} display The display to check.

In our case we could ask:

    test = myMarkerContainer.isVisible(map);

Again, this would result in “true”.

With the getParent (display) we can get the parent of the map object.


{ovi.mapsapi.map.Display} display The display for which to return the parent object.

Returns: {ovi.mapsapi.map.Object} The parent object of this object for the given display or undefined if this map object has no parent.

    test = myMarkerContainer.getParent(map);

If we want to get the Display names that the Container is attached to, this could be queried as follows:

    test = myMarkerContainer.getDisplays();

This case we would know already there is the “map” Display, so requesting now the question myMarkerContainer.isAdded (test) would give us “true”, because myMarkerContainer is attached to the “map”.

Example code

Here is a full example with required HTML and embedded JavaScript.

<title>Marker on the Map</title>
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
<div id="map" style="z-index: -1; left:0px; top:0px; width: 100%; height: 100%; position: absolute;"></div>
<script type="text/javascript">
// Set the authentication token, which is needed by the web-services to authenticate your application.
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
var map = new ovi.mapsapi.map.Display(document.getElementById("map"), {'zoomLevel':8, 'center':[53.1, 15.1]});
map.set("baseMapType", map.SATELLITE);
myMarker = new ovi.mapsapi.map.Marker([52.52,13.4]);
var myContainer = new ovi.mapsapi.map.Container()

For more on Ovi Maps API

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


Tested on

Google Chrome 11.0x

Mozilla Firefox 5.0

538 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.