×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Using the geocoding service

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
avnee.nathani (Talk | contribs)
(Avnee.nathani - Updated article for Nokia Maps Javascript API v2.0. (Released in Dec 2011))
Line 4: Line 4:
 
In this example we will create a small online tool for the user to search the globe for a city, country and so on.
 
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.
+
We will utilize the Nokia 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
 
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
Line 14: Line 14:
 
==Prerequisites==
 
==Prerequisites==
  
Ovi Maps API supported web browser (basically any modern web browser)
+
Nokia  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==
 
==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
+
Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. Please read the [http://www.developer.nokia.com/Develop/Maps/Quota/ Location API Business Models and Usage Restrictions page] to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials from the [https://api.developer.nokia.com/ovi-api Nokia Developer API Registration page].
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"
+
  
 
==Implementation==
 
==Implementation==
Line 37: Line 32:
 
located in the center of the viewport.  
 
located in the center of the viewport.  
  
"var searchTermThe object used for the search var searchTerm
+
<tt>var searchTerm</tt> The object used for the search var searchTerm
"rs" is the search result
+
<tt>rs</tt> is the search result
  
The searchManager is instantiated with : var searchManager = new ovi.mapsapi.search.Manager();
+
The searchManager is instantiated with : <tt>var searchManager = new nokia.maps.search.Manager();</tt>
  
The check for "if(value == "finished")" will define what will happen when the search is finished.
+
The check for <tt>if(value == "finished")</tt> 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.
+
With the <tt>rs = (new nokia.maps.search.component.SearchResultSet(observedManager.locations)).container;</tt> we will put the Markers on the map.
  
The "bbox = new ovi.mapsapi.geo.BoundingBox..." sets a fixed bounding box.
+
The <tt>bbox = new nokia.maps.geo.BoundingBox...</tt> sets a fixed bounding box.
  
  
Line 54: Line 49:
 
<html>
 
<html>
 
<head>
 
<head>
    <script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8">
+
<script type="text/javascript"
    </script>
+
    src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
 +
</script>
 
       <link rel="stylesheet" href="style.css" />
 
       <link rel="stylesheet" href="style.css" />
 
</head>
 
</head>
Line 71: Line 67:
 
var map;
 
var map;
  
map = new ovi.mapsapi.map.Display(document.getElementById("map"),  
+
map = new nokia.maps.map.Display(document.getElementById("map"),  
 
{
 
{
  
     components: [ new ovi.mapsapi.map.component.Behavior(),
+
     components: [ new nokia.maps.map.component.Behavior(),
                 new ovi.mapsapi.map.component.ZoomBar(),
+
                 new nokia.maps.map.component.ZoomBar(),
                 new ovi.mapsapi.map.component.Overview(),                             
+
                 new nokia.maps.map.component.Overview(),                             
                 new ovi.mapsapi.map.component.TypeSelector(),     
+
                 new nokia.maps.map.component.TypeSelector(),     
                 new ovi.mapsapi.map.component.ScaleBar()],
+
                 new nokia.maps.map.component.ScaleBar()],
 
     'zoomLevel': 3,  
 
     'zoomLevel': 3,  
 
});
 
});
Line 86: Line 82:
 
                 rs,  
 
                 rs,  
 
                 prox = {
 
                 prox = {
                     center: new ovi.mapsapi.geo.Coordinate(52.5, 13.3333),  
+
                     center: new nokia.maps.geo.Coordinate(52.5, 13.3333),  
 
                     radius: 1200
 
                     radius: 1200
 
                 },
 
                 },
                 bbox = new ovi.mapsapi.geo.BoundingBox(  
+
                 bbox = new nokia.maps.geo.BoundingBox(  
                     new ovi.mapsapi.geo.Coordinate(50.1146125793467, 8.68348503112893),
+
                     new nokia.maps.geo.Coordinate(50.1146125793467, 8.68348503112893),
                     new ovi.mapsapi.geo.Coordinate(50.07635498046865, 8.517169952392568)
+
                     new nokia.maps.geo.Coordinate(50.07635498046865, 8.517169952392568)
 
                 );
 
                 );
   var searchManager = new ovi.mapsapi.search.Manager();
+
   var searchManager = new nokia.maps.search.Manager();
 
             searchManager.addObserver("state", function(observedManager, key, value) {
 
             searchManager.addObserver("state", function(observedManager, key, value) {
 
                 if(value == "finished") {
 
                 if(value == "finished") {
 
                     if (observedManager.locations.length > 0) {
 
                     if (observedManager.locations.length > 0) {
 
                         if (rs) map.objects.remove(rs);
 
                         if (rs) map.objects.remove(rs);
                         rs = (new ovi.mapsapi.search.component.SearchResultSet(observedManager.locations)).container;
+
                         rs = (new nokia.maps.search.component.SearchResultSet(observedManager.locations)).container;
  
 
                         alert("SEARCH ENDED SUCCESSFULLY");
 
                         alert("SEARCH ENDED SUCCESSFULLY");
Line 121: Line 117:
 
</code>
 
</code>
  
 +
==For more on Nokia Maps API==
  
==For more on Ovi Maps API==
+
Please check out the Nokia Maps API full documentation and API reference here:
 +
* http://api.maps.nokia.com/
  
Please check out the Ovi Maps API full documentation and API reference here:
+
You may also access the interactive Nokia Maps API playground,
 
+
* http://api.maps.nokia.com/2.1.0/playground/index.html
http://api.maps.ovi.com
+
  
 
==Tested with==
 
==Tested with==
  
Google Chrome 11.0x
+
* Google Chrome 11.0x
 
+
* Mozilla Firefox 5.0
Mozilla Firefox 5.0
+

Revision as of 13:48, 31 December 2011

Contents

Introduction

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


Prerequisites

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

Important about Maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. Please read the Location API Business Models and Usage Restrictions page to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials from the Nokia Developer API Registration page.

Implementation

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 nokia.maps.search.Manager();

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

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

The bbox = new nokia.maps.geo.BoundingBox... sets a fixed bounding box.


Example code

<html>
<head>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
</script>
<link rel="stylesheet" href="style.css" />
</head>
<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()">
<br>
</div>
</body>
<script type="text/javascript">
 
 
var map;
 
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()],
'zoomLevel': 3,
});
 
function mapStartGeoCode(){
var searchTerm,
rs,
prox = {
center: new nokia.maps.geo.Coordinate(52.5, 13.3333),
radius: 1200
},
bbox = new nokia.maps.geo.BoundingBox(
new nokia.maps.geo.Coordinate(50.1146125793467, 8.68348503112893),
new nokia.maps.geo.Coordinate(50.07635498046865, 8.517169952392568)
);
var searchManager = new nokia.maps.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 nokia.maps.search.component.SearchResultSet(observedManager.locations)).container;
 
alert("SEARCH ENDED SUCCESSFULLY");
map.objects.add(rs);
map.zoomTo(rs.getBoundingBox(), true);
}
} else if(value == "failed") {
 
alert("SEARCH FAILED.");
}
});
 
var geocode = document.getElementById("geo_text_box");
alert(geocode.value);
searchTerm = geocode.value;
searchManager.geocode(searchTerm, prox);
}
</script>
</html>
<code java>

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,

Tested with

  • Google Chrome 11.0x
  • Mozilla Firefox 5.0
964 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.

×