(Difference between revisions)

HERE Maps API - Create map markers from XML data

From Nokia Developer Wiki
Jump to: navigation, search
rahulvala (Talk | contribs)
m (Rahulvala -)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update of Template:ArticleMetaData)
Line 3: Line 3:
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|platform= Web browser
|platform= Web browser
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
|id= <!-- Article Id (Knowledge base articles only) -->
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
|review-timestamp= <!-- After re-review: YYYYMMDD -->

Revision as of 01:33, 2 January 2012

This article explains how to read a structured XML file and create map markers based on the data.

Article Metadata
Platform(s): Web browser
Created: Maveric (27 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: hamishwillee (02 Jan 2012)



Sometimes it would be useful to have the data for map, e.g. for markers, to reside on a separate file. In this article, an example is presented, using which you can yourself utilize a separate XML file for creating map content. The example will use Javascript and jQuery.


  • Nokia Maps API supported web browser (basically any modern web browser).
  • JQuery downloaded and installed.
  • Change the directory names for your own version of the example, if needed.

Example code

Note that the example code leaves you room to implement your own infoBubbles and some other functionality is there if you need it, otherwise you can remove it; for e.g. the behaviour of the map and availability of components. Feel free to copy and modify for your own purposes!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title>Nokia Maps API example - Multiple markers created from XML data</title>
<body onLoad="init();">
<p style="text-align: center;">- Nokia MAPS API EXAMPLE -</p>
<div id="map" style="width:600px; height:400px; position: relative"></div>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="js/markers.js"></script>
var markerCoords;
var mapContainer;
var container;
var myMap;
var bubbles=new Array();
// When the HTML page body section is loaded this function will be called.
function init(){
// Here we create an Nokia Maps within a Container.
mapContainer = document.getElementById("map");
myInfoBubbles = new nokia.maps.map.component.InfoBubbles();
myMap = nokia.maps.map,
map = new myMap.Display(mapContainer, {
center: [52.59, 13.3], zoomLevel: 10,
components: [ new myMap.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar(),
myInfoBubbles ]
container = new nokia.maps.map.Container();
// Define the XML filename to read that contains the marker data
// This function gets passed the marker XML data file name
function placeMarkersOnMaps(filename)
var counter = 0;
$.get(filename, function(xml){
//Read the name, address, latitude and longitude for each Marker
var name = $(this).find('name').text();
var address = $(this).find('address').text();
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
//Used for testing:
//alert("Name:"+name+" Address:"+address+" Lat:"+lat+" Lon:"+lng);
//Put each marker on the map as the data has been read.
markerCoords = new nokia.maps.geo.Coordinate(parseFloat(lat), parseFloat(lng));
marker = new nokia.maps.map.StandardMarker(markerCoords,
{text:name, brush:"#FF69B4", pen:"#09F911", textPen:"#00009C", shape: "star"});
// Used for testing:
// myInfoBubbles.addBubble(name, markerCoords);
// counter ++ 1;
// alert(counter);
// Add the marker container .
// Zoom into the markers.
alert("Markers have been loaded. Hit OK to zoom the map into the area covering the markers.");
map.zoomTo(container.getBoundingBox(), false);

Example XML file

<?xml version="1.0"?>
<address>ADDRESS 1</address>
<address>ADDRESS 2</address>
<address>ADDRESS 3</address>
<address>ADDRESS 4</address>
<address>ADDRESS 5</address>
<address>ADDRESS 6</address>
<address>ADDRESS 7</address>
<address>ADDRESS 8</address>


Edit the script and file for your own purposes, hope you find this article useful.

Tested with

Microsoft XP Pro and the following browsers:

  • Opera 5.0.5 & Firefox 5.0

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,

214 page views in the last 30 days.