×
Namespaces

Variants
Actions
Revision as of 10:55, 27 October 2011 by Maveric (Talk | contribs)

HERE Maps API - How to display KML file data on the map

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Introduction

The version 2.0 of Nokia Maps API offers support for KML data formatted files and displaying the containing data on the Nokia Maps. This article will offer an overview to KML, structure and how it can be used within Nokia Maps.

Summary

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

Important about Nokia 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.For more information on how to obtain the credentials, please start with the Nokia Maps API Developers Guide section "Acquiring API credentials"

Implementation

Nokia Maps API has built in support for KML. It is an abbreviation for Keyhole Markup Language, representing an XML notation for expressing geographic annotation and visualization within Internet-based, two-dimensional maps and three-dimensional Earth browsers. KML was developed as a Google Maps feature by company called Keyhole, Inc, later acquired by Google.

Today, KML is an international standard of the Open Geospatial Consortium (http://en.wikipedia.org/wiki/Open_Geospatial_Consortium) and is supported in the Nokia Maps API.

Restrictions in Nokia Maps

Nokia Maps API does not currently support 3D so, these values if prNokiaded would be discarded by the API.- Nokia Maps API does not currently support reading packaged KMZ files.

Strucure

KML is structured as tag-based, with nested-elements and attributes and based on the XML standard. The tags are case-sensitive and they must appear exactly as they are listed in the official KML Reference, found within the OGC pages. The KML Reference indicates which tags are optional. Within a given element, tags must appear in the order shown in the Reference. The KML file can contain information for Markers, Places, images, Polygons, 3D models, textual descriptions, and so on. Common for all items placed is that they always have a longitude and a latitude. Additional data e.g. tilt, heading and altitude can be prNokiaded as "camera view". The KML file specifies a set of features (placemarks, images, polygons, 3D models, textual descriptions, etc.)

Example KML document

In this example we will have a simple KML document containing data for one Placemark, for Berlin, Alexanderplatz.

Please note that by the KML specification the coordinate is given in format: longitude, latitude.

File: kml_data_file.kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Berlin</name>
<description>Alexanderplatz, Berlin, Germany</description>
<Point><coordinates>13.41156,52.526666</coordinates></Point>
</Placemark>
</Document>
</kml>

Example code

<html>
<head>
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.0.0/jsl.js?kml=auto"></script>
</head>
<body>
<div id="map" style="width:100%; height:100%;"></div>
<script type="text/javascript">
 
var map = new nokia.maps.map.Display(document.getElementById("map"),
{ components: [ new nokia.maps.map.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(),
new nokia.maps.map.component.InfoBubbles()],
'zoomLevel': 4, 'center':[53.1, 13.1]});
 
var kml = new nokia.maps.kml.Manager(),
resultSet, container;// Create a callback function for parsing the KML file
 
// then push the parsing result to map display:
var onParsed = function (kmlManager)
{
 
// Check if the parsing was successfully finished:
if (kmlManager.state == "finished")
{
 
// If all OK, go ahead and parse the KML file by KMLResultSet:
resultSet = new nokia.maps.kml.component.KMLResultSet(kmlManager.kmlDocument, map);
container = resultSet.container;
 
// Push map objects & container to the map Display:
map.objects.add(container);
 
// Zoom the map to cover the area, uncomment this if you want.
// map.zoomTo(container.getBoundingBox());
 
}};
 
// Add an observer to the KML Manager
kml.addObserver("state", onParsed);
 
// Start parsing a kml file with given url
// Note: Modify the URL / local file path according to your implementation.
 
kml.parseKML("http://my_domain.com/" + "kml_data_file.kml");//
 
</script>
</body>
</html>


See this example online here

http://mapswidgets.com

Geodetic reference systems in KML

For its reference system, KML uses 3D geographic coordinates: longitude, latitude and altitude, in that order. The longitude, latitude components are defined by the World Geodetic System of 1984 (WGS84). The vertical component (altitude) is measured from the WGS84 EGM96 Geoid vertical datum. If altitude is omitted from a coordinate string, e.g. (-122.917, 49.2623) then the default value of 0 (approximately sea level) is assumed for the altitude component, i.e. (-122.917, 49.2623, 0) is assumed. A formal definition of the coordinate reference system (encoded as GML) used by KML is contained in the OGC KML 2.2 Specification. This definition references well-known EPSG CRS components.

OGC standard process

The KML 2.2 specification was submitted to the Open Geospatial Consortium to assure its status as an open standard for all geobrowsers. In November 2007 a new KML 2.2 Standards Working Group was established within OGC to formalize KML 2.2 as an OGC standard. Comments were sought on the proposed standard until January 4, 2008,[4] and it became an official OGC standard on April 14, 2008.[5]

For more on Nokia Maps API

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

http://api.maps.nokia.com==

Tested with

Google Chrome: 14.0.835.202 m Mozilla Firefox 8.0 O/S Windows XP Professional 32bit

950 page views in the last 30 days.
×