×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Question Nokia MAP : Route distance

    Dear All ..

    Reference :
    http://api.maps.nokia.com/2.0.0/playground/index.html
    specialy the : " Create route from A to B " example.

    I also read http://api.maps.nokia.com/2.0.0/apir....html#distance

    Question :
    Using that example, how to get and display the "distance" value ?

    Sincerely
    -bino-

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Nokia MAP : Route distance

    You have the API docs link there, thus when you get teh reply for teh route, you use the distance variable which then shows the distance, thus not really understanding the question here..

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Re: Nokia MAP : Route distance

    Dear symbianyucca

    Thankyou for your response.

    Quote Originally Posted by symbianyucca View Post
    You have the API docs link there, thus when you get teh reply for teh route, you use the distance variable which then shows the distance, thus not really understanding the question here..
    Maybe this caused by my minimum knowledge of javascript

    I try this code :
    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://api.maps.nokia.com/2.0.0/jsl.js" type="text/javascript" charset="utf-8"></script>
    <script>
    var router = new nokia.maps.routing.Manager(); // create a route manager;
    var modes = [{
    type: "shortest",
    transportModes: ["car"],
    options: "avoidTollroad",
    trafficMode: "default"
    }];

    var onRouteCalculated = function (observedRouter, key, value) {
    document.getElementById('mydebug').innerHTML= "Debug >> Call : OnRouteCalculated";

    if (value == "finished") {
    document.getElementById('mydebug').innerHTML= "Finished";
    var routes = observedRouter.getRoutes();
    var routesumary = new nokia.maps.routing.RouteSummary(routes[0]);
    //document.getElementById('mydebug').innerHTML= "from " + loc1 + " , to " + loc2 ;
    document.getElementById('distance').innerHTML= "Distance : " + routesumary.distance ;
    document.getElementById('mydebug').innerHTML= "Debug >> ";

    } else if (value == "failed") {
    document.getElementById('mydebug').innerHTML= "Debug >> Failed : OnRouteCalculated";
    }
    };

    /* We create on observer on router's "state" property so the above created
    * onRouteCalculated we be called once the route is calculated
    */
    router.addObserver("state", onRouteCalculated);

    function calculateDistance() {
    document.getElementById('mydebug').innerHTML= "Debug >> CAll : Calculate Distance";
    // Create waypoints
    var waypoints = new nokia.maps.routing.WaypointParameterList();
    waypoints.addCoordinate(new nokia.maps.geo.Coordinate(document.forms[0].loc1lat.value, document.forms[0].loc1lon.value));
    waypoints.addCoordinate(new nokia.maps.geo.Coordinate(document.forms[0].loc2lat.value, document.forms[0].loc2lon.value));
    router.calculateRoute(waypoints, modes);
    document.getElementById('mydebug').innerHTML= "Debug >> End : Calculate Distance";

    }


    </script>

    </head>
    <body style="font-family: Arial; font-size: 13px; color: red;">
    <form action="#" onsubmit="calculateDistance(); return false;">
    <p>
    <input type="text" name="loc1lat" value="-7.779625" size="20" />
    <input type="text" name="loc1lon" value="110.376602" size="20" />
    <input type="text" name="loc2lat" value="-7.782283" size="20" />
    <input type="text" name="loc2lon" value="110.367696" size="20" />
    <input type="submit" name="find" value="Search" />
    </p>
    </form>
    <div id="mydebug">Debug >> </div>
    <div id="duration">Duration: </div>
    <div id="distance">Distance: </div>
    <script type="text/javascript">
    // Authentication set up is the first thing that you must do with the API
    nokia.maps.util.ApplicationContext.set({"appId": "myapid", "authenticationToken": "mytoken"});
    </script>
    </body>
    </html>
    Whit this code, I want it display the "distance" betwen 2 location when I press the submit button.

    But the script stoped at "Debug >> CAll : Calculate Distance" line.

    Sincerely
    -bino-

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Nokia MAP : Route distance

    You might want to try using FireFox and Firebug, then you might get better idea on what is going wrong with your code.

    Also you could check my examples: http://www.developer.nokia.com/Commu...r_Ovi_Maps_API anyway, appears that I forgot to copy last two examples to my server.. All and all, you can use the one found in wiki.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Re: Nokia MAP : Route distance

    Dear Sir
    Quote Originally Posted by symbianyucca View Post
    Also you could check my examples: http://www.developer.nokia.com/Commu...r_Ovi_Maps_API anyway, appears that I forgot to copy last two examples to my server.. All and all, you can use the one found in wiki.
    I realy appreciate your enlightment .... it works !!

    Here is my dirty adaptation of your codes
    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://api.maps.nokia.com/2.0.0/jsl.js" type="text/javascript" charset="utf-8"></script>
    <script>
    var router = new nokia.maps.routing.Manager(); // create a route manager;
    var modes = [{
    type: "fastestNow",
    transportModes: ["car"],
    options: "avoidTollroad",
    trafficMode: "default"
    }];

    var onRouteCalculated = function (observedRouter, key, value) {
    document.getElementById('mydebug').innerHTML= "Debug >> Call : OnRouteCalculated";

    if (value == "finished") {
    document.getElementById('mydebug').innerHTML= "Finished";
    var routes = observedRouter.getRoutes();
    //var routesumary = new nokia.maps.routing.RouteSummary(routes[0]);
    //document.getElementById('mydebug').innerHTML= "from " + loc1 + " , to " + loc2 ;
    document.getElementById('distance').innerHTML= "Distance : " + routes[0].totalLength +' meters';
    document.getElementById('mydebug').innerHTML= "Debug >> ";

    } else if (value == "failed") {
    document.getElementById('mydebug').innerHTML= "Debug >> Failed : OnRouteCalculated";
    }
    };


    function calculateDistance() {
    document.getElementById('mydebug').innerHTML= "Debug >> CAll : Calculate Distance";
    // Create waypoints
    var waypoints = new nokia.maps.routing.WaypointParameterList();
    document.getElementById('mydebug').innerHTML += ", Create waypoints";
    var lat1 = parseFloat(document.forms[0].loc1lat.value);
    var lon1 = parseFloat(document.forms[0].loc1lon.value);
    var lat2 = parseFloat(document.forms[0].loc2lat.value);
    var lon2 = parseFloat(document.forms[0].loc2lon.value);
    /* We create on observer on router's "state" property so the above created
    * onRouteCalculated we be called once the route is calculated
    */
    router.addObserver("state", onRouteCalculated);
    waypoints.addCoordinate(new nokia.maps.geo.Coordinate(lat1,lon1));
    waypoints.addCoordinate(new nokia.maps.geo.Coordinate(lat2,lon2));
    router.calculateRoute(waypoints, modes);
    document.getElementById('mydebug').innerHTML= "Debug >> End : Calculate Distance";
    }


    </script>

    </head>
    <body style="font-family: Arial; font-size: 13px; color: red;">
    <form action="#" onsubmit="calculateDistance(); return false;">
    <p>
    <input type="text" name="loc1lat" value="-7.779625" size="20" />
    <input type="text" name="loc1lon" value="110.376602" size="20" />
    <input type="text" name="loc2lat" value="-7.782283" size="20" />
    <input type="text" name="loc2lon" value="110.367696" size="20" />
    <input type="submit" name="find" value="Search" />
    </p>
    </form>
    <div id="mydebug">Debug >> </div>
    <div id="duration">Duration: </div>
    <div id="distance">Distance: </div>
    <script type="text/javascript">
    // Authentication set up is the first thing that you must do with the API
    nokia.maps.util.ApplicationContext.set({"appId": "myAppId", "authenticationToken": "myToken"});
    </script>
    </body>
    </html>
    Sincerely
    -bino-

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Nokia MAP : Route distance

    good to hear that those codes are usefull, also note that if you want to later on make device side client, then there are same use cases made with different technologies also available there.

Similar Threads

  1. Replies: 5
    Last Post: 2011-01-05, 15:04
  2. route and record route on 3rd edition
    By jcaradec in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-04-16, 19:07
  3. Record-Route and Route at SIP
    By mhappenhofer in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-11-30, 09:22
  4. Nokia Prototype SDK 3.0, Route Tool, JSR 179 support
    By bruce76 in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2005-07-08, 15:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×