Revision as of 18:37, 20 December 2013 by jasfox (Talk | contribs)

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

HERE Maps API - Create map markers from XML data

From Nokia Developer Wiki
Jump to: navigation, search

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

Article Metadata
Code ExampleTested with
Devices(s): Internet Explorer, Firefox, Opera, Google Chrome
Platform(s): Web browser
Dependencies: HERE Maps 2.5.3 or higher
Keywords: HERE Maps, jQuery, JavaScript, XML, KML
Created: Maveric (27 Jun 2011)
Updated: jasfox (31 Dec 2011)
Last edited: jasfox (20 Dec 2013)



Sometimes it is useful to have the data for a map, e.g. markers, in a separate file. This article provides an example which you can use to generate map content from an XML file. The example uses JavaScript and jQuery, and processes an XML data file of the following format:

<?xml version="1.0"?>
<address>ADDRESS 1</address>


  • HERE 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

When the HTML page body section is loaded the loadXMLFile() method will be called. The location of the XML file is relative to the URL of the HTML page.

Note.pngNote: Both files must be hosted on a server for this function to work. The err method will fire if the file cannot be accessed.

function loadXMLFile(){
var filename = './data/markers.xml';
type: "GET",
url: filename ,
dataType: "xml",
success: parseXML,
error : onXMLLoadFailed

When an error occurs a simple alert() is shown:

function onXMLLoadFailed(){
alert("An Error has occurred.");

The parseXml() function is the meat of the example. It uses standard jQuery parsing to retrieve the elements from the XML file.

function parseXML(xml){
container = new nokia.maps.map.Container();
//Read the name, address, latitude and longitude for each Marker
var nme = $(this).find('name').text();
var address = $(this).find('address').text();
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var markerCoords = new nokia.maps.geo.Coordinate
(parseFloat(lat), parseFloat(lng));
container.objects.add(new nokia.maps.map.StandardMarker(
markerCoords, {text:nme}));
map.zoomTo(container.getBoundingBox(), false);

Example XML file

The file to be parsed is in the following format - the full XML file can be found in markers.xml

<?xml version="1.0"?>
<address>ADDRESS 1</address>
.... etc


The following screenshot shows how the XML has been parsed


A fully working example can be found at:


Alternative Solution

Since the latest version of the HERE Maps API is able to natively render KML files, it would make sense to transform the XML into KML using XSLT. You can copy the markers.xml file from markers.xml into an XSLT Editor and use the the XSLT stylesheet described below.The KML can then be loaded directly onto a map using the code from the Loading a KML file example on the API explorer

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="markers">
<xsl:for-each select="marker">
<name><xsl:value-of select="name"/></name>
<address><xsl:value-of select="address"/></address>
<xsl:value-of select="lat"/>,<xsl:value-of select="lng"/>,0

For more on the HERE Maps API

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

You may also access the interactive API explorer

This page was last modified on 20 December 2013, at 18:37.
279 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.