×
Namespaces

Variants
Actions
Revision as of 14:46, 28 November 2013 by jasfox (Talk | contribs)

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

HERE Maps API - Performing multiple concurrent search requests

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Internet Explorer, Google Chrome , Firefox, Opera
Compatibility
Platform(s): Web
Dependencies: HERE Maps API 2.5.3
Article
Keywords: HERE Maps, JavaScript, Search
Created: Maveric (25 Oct 2011)
Last edited: jasfox (28 Nov 2013)

Contents

Introduction

In this article we will examine the following usage of the HERE Maps API.

  1. Multiple addresses exist, a total of 10 for this example.
  2. A Map Marker is needed to be displayed for each of the addresses.
  3. Finally the ZoomLevel needs to be set to cover all of the Markers.

This article enforces the correct use of the search.Manager in case of multiple concurrent requests.

Prerequisites

HERE Maps API supported web browser (basically any modern web browser).

Important note about maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but you must obtain and use authentication and authorization credentials to use the services. Please read the Terms and Conditions and check the Pricing Plans 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 free for free following the instructions here

Implementation

function concurrentSearch(map){
// we will put our address markers into this container
addressContainer = new nokia.maps.map.Container();
managersFinished = 0;
 
//Addresses to be displayed
addresses = ["Helsinki, Finland", "Zaragoza, Spain", "Berlin, Germany",
"Colorado Springs, USA", "Houston, TX", "London, UK", "Vancouver, Canada",
"Hyderabad, India", "Beijing, China", "Ilomantsi, Finland" ];
var i = addresses.length;
 
// iterate over all addresses, create a manager for each of them,
// add the observer and call the geocode method
 
while(i--) {
nokia.places.search.manager.geoCode({
searchTerm :addresses[i],
onComplete: onSearchComplete
});
}
}
function onSearchComplete(data, requestStatus) {
if (requestStatus == "OK") {
// if we are finished, we add a marker for the mapped position
addressContainer.objects.add(
new nokia.maps.map.StandardMarker(data.location.position));
//increment the counter to notify another manager has finished
managersFinished++;
} else if(requestStatus === "ERROR") {
// we'll also increment in case of an error
managersFinished++;
}
 
// if all managers are finished, we call the final function
if(managersFinished === addresses.length) {
onAllManagersFinished();
}
}
function onAllManagersFinished() {     
//we get the bounding box of the container
var bbox = addressContainer.getBoundingBox();
 
// if the bounding box is null then there are no objects inside
// meaning no markers have been added to it
 
if (bbox != null) {
// we have at least one address mapped
// so we add the container and zoomTo it
map.objects.add(addressContainer);
map.zoomTo(bbox, true);
} else {
// otherwise we'll pop up an error message
alert("There are no addresses to show :(");
}
}


Concurrent-search.png

A fully working example can be found at:

http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/demos/concurrent-search-requests/index.html

This page was last modified on 28 November 2013, at 14:46.
258 page views in the last 30 days.