Talk:HERE Maps API - How to calculate a route between two points

From Nokia Developer Wiki
Jump to: navigation, search

Collandres - Re: How to calculate a route between two points

Hello, I'm trying to calculate a route between two (or more) points by using the address of the cities I want to add to the itinerary. After the initialization of the search.Managers I made a "SEARCH3.maxResults=1;" in order to have just one point per search so the itinerary may be found. I'm having a lot of troubles with the waypoints.addLocation and waypoints.addPlace functions, my code is :

                                               var SEARCH1 = new ovi.mapsapi.search.Manager();

var SEARCH2 = new ovi.mapsapi.search.Manager(); SEARCH1.maxResults=1; SEARCH2.maxResults=1; adr1 = "Paris"; adr2 = "Dijon"; SEARCH1.placeSearch("\'"+adr1+"\'"); SEARCH2.placeSearch("\'"+adr2+"\'");

var router = new ovi.mapsapi.routing.Manager(); //create waypoints var waypoints = new ovi.mapsapi.routing.WaypointParameterList(); waypoints.addPlace(SEARCH1.places[0]); waypoints.addPlace(SEARCH2.places[0]); var modes = [{ type: "shortest", transportModes: ["car"], options: "avoidTollroad", trafficMode: "default" }];

var onRouteCalculated = function(observedRouter, key, value){ if (value == "finished") { var routes = observedRouter.getRoutes(); var mapRoute = new ovi.mapsapi.routing.component.RouteResultSet(routes[0]).container; map.objects.add(mapRoute); map.zoomTo(mapRoute.getBoundingBox(), false, "default"); } else if (value == "failed") { alert("The routing request failed."); } };

//add the observer function to the router\'s "state" property router.addObserver("state", onRouteCalculated);

//calculate the route (and call onRouteCalculated afterwards) router.calculateRoute(waypoints, modes);

In this case I would like a route from Paris to Dijon as you can see, a little help would be very usefull! Thanks,


collandres 15:24, 27 June 2011 (EEST)

Avnee.nathani - Article rename

I've updated the article to Nokia Maps Javascript API v2.0 - updated/ added new code, added screenshot, removed broken links, rebranded to 'Nokia Maps', etc. The article needs to be renamed to Nokia Maps API - How to...


avnee.nathani 12:34, 31 December 2011 (EET)


Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.