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

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

HERE Maps API - Using the geocoding service

From Nokia Developer Wiki
Jump to: navigation, search



In this example we will create a small online tool for the user to search the globe for a city, country and so on.

We will utilize the Ovi Maps Search and geocoding service for this.

The user can enter any string to the text box and if the search text can be geocoded to a physical location, we will put a Marker on the map for each of the found target on the result list.

For example a search for "Berlin" would result in several map Markers, as there are more than one city on the globe with that name.


Ovi 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 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"


The full example code is provided below.

Comments on the code

We will utilize the zoomTo to cover all the findings, so the map will be zoomed out far enough for them all to become visible. For the zoomTo we must provide the name of the boundingBox, keepCenter (false by default) and optionally animation name.

If the keepCenter flag is used (true) the size of the viewport will be increased such that the original map center is still located in the center of the viewport.

"var searchTerm" The object used for the search var searchTerm "rs" is the search result

The searchManager is instantiated with : var searchManager = new ovi.mapsapi.search.Manager();

The check for "if(value == "finished")" will define what will happen when the search is finished.

With the "rs = (new ovi.mapsapi.search.component.SearchResultSet(observedManager.locations)).container;" we will put the Markers on the map.

The "bbox = new ovi.mapsapi.geo.BoundingBox..." sets a fixed bounding box.

Example code

<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8">
<link rel="stylesheet" href="style.css" />
<div id="map" style="width:100%; height:80%;"></div>
<body style = "width:80%; height:80%;">
<div id="extra">
<input type=text id="geo_text_box">
<INPUT TYPE=BUTTON VALUE="Geo code with name" ONCLICK="mapStartGeoCode()">
<script type="text/javascript">
var map;
map = new ovi.mapsapi.map.Display(document.getElementById("map"),
components: [ new ovi.mapsapi.map.component.Behavior(),
new ovi.mapsapi.map.component.ZoomBar(),
new ovi.mapsapi.map.component.Overview(),
new ovi.mapsapi.map.component.TypeSelector(),
new ovi.mapsapi.map.component.ScaleBar()],
'zoomLevel': 3,
function mapStartGeoCode(){
var searchTerm,
prox = {
center: new ovi.mapsapi.geo.Coordinate(52.5, 13.3333),
radius: 1200
bbox = new ovi.mapsapi.geo.BoundingBox(
new ovi.mapsapi.geo.Coordinate(50.1146125793467, 8.68348503112893),
new ovi.mapsapi.geo.Coordinate(50.07635498046865, 8.517169952392568)
var searchManager = new ovi.mapsapi.search.Manager();
searchManager.addObserver("state", function(observedManager, key, value) {
if(value == "finished") {
if (observedManager.locations.length > 0) {
if (rs) map.objects.remove(rs);
rs = (new ovi.mapsapi.search.component.SearchResultSet(observedManager.locations)).container;
map.zoomTo(rs.getBoundingBox(), true);
} else if(value == "failed") {
alert("SEARCH FAILED.");
var geocode = document.getElementById("geo_text_box");
searchTerm = geocode.value;
searchManager.geocode(searchTerm, prox);
<code java>

For more on Ovi Maps API

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


Tested with

Google Chrome 11.0x

Mozilla Firefox 5.0

939 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.