×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Question Doubt using RouteSummary() method

    Hi,

    i'm developing a webapp and i'm having some troble with the use of the method RouteSummary() and to clear a route already routed. My code is:


    <script type="text/javascript">
    var way;
    function val(what) {
    way = what.value;
    load();
    }

    var locat = null;
    var end = null;
    var container = null;
    var map;
    var MyinfoBubbles;
    var router;
    var waypoints;
    var resum;

    //if(getUrlVars()['maps']=='nokia'||getUrlVars()['maps']=='false') {
    nokia.Settings.set( "appId", "MYKEY");
    nokia.Settings.set( "authenticationToken", "MYKEY");
    $(document).ready(function () {

    map = new nokia.maps.map.Display(document.getElementById("mapContainer"), {
    'center': [-22.9069, -47.0613],
    'zoomLevel': 17,
    components: [ new nokia.maps.map.component.Behavior() ]
    });
    load();
    });

    function load() {
    var timeoutVal = 10 ;
    navigator.geolocation.getCurrentPosition(success, error,
    { enableHighAccuracy: false, timeout: timeoutVal, maximumAge: 0 });
    }
    function error(msg) {
    switch(msg.code)
    {
    case msg.PERMISSION_DENIED:
    //alert("User denied the request for Geolocation.");
    alert("Para utilizar o CLOG é necessário aceitar o compartilhamento de sua localização.");

    break;
    case msg.POSITION_UNAVAILABLE:
    alert("O nao conseguiu obter sua localização.");

    break;
    case msg.TIMEOUT:
    //alert("The request to get user location timed out.");
    alert("O tempo maximo de busca de sua localização foi excedido.");

    break;
    case msg.UNKNOWN_ERROR:
    alert("An unknown error occurred.");

    break;
    }

    }
    function success(position) {
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    locat = new nokia.maps.geo.Coordinate(lat, lon);
    nokia.places.search.manager.reverseGeoCode({
    latitude: lat,
    longitude: lon
    });


    var waypoints = new nokia.maps.routing.WaypointParameterList();
    waypoints.addCoordinate(locat);
    waypoints.addCoordinate(new nokia.maps.geo.Coordinate(-29.915393,-49.051036));

    var modes = [{
    type: "shortest",
    transportModes: [way],
    options: "",
    trafficMode: "default"
    }];

    router = new nokia.maps.routing.Manager();
    var onRouteCalculated = function (observedRouter, key, value) {
    if (value == "finished") {
    //map.set(null);
    var routes = observedRouter.getRoutes();
    mapRoute = new nokia.maps.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.");
    }
    };
    router.addObserver("state", onRouteCalculated);
    router.calculateRoute(waypoints, modes.slice(0));
    //router.calculateRoute(waypoints, modes);

    }
    //}


    </script>
    <style type="text/css">
    #mapContainer {

    position:absolute;
    top:35px;
    left:0;
    display:block;
    height: 94%;
    width: 100%;

    }

    #up{
    width: 106%;
    height: 40px;
    margin-left:-10px;
    margin-top: -10px;
    text-align: center;
    letter-spacing: 30%;
    white-space: nowrap;
    overflow: hidden;
    background-color:#000;
    color:#FFF;


    }

    a:visited {color: #ffffff;}
    a:link {color: #ffffff;}
    a:bover {color: #000000;}
    a:active {color: #000000;}
    </style>

    </head>
    <body>
    <div id="up">

    <input class="button" type="button" value="pedestrian" onClick="val(this)">
    <input class="button" type="button" value="publicTransport" onClick="val(this)">
    <input class="button" type="button" value="car" onClick="val(this)">

    <div id="mapContainer"></div>

    </div>

    So, when the user clicks on the button pedestrian, publicTransport or Car, the app will trace another route with the selected option, but in my case, it traces as many as the user click, so i need to update the new route to not show the older anymore.

    In the RouteSummary() method, i want to show the average time to the user reach his destination, but i can do this because i don't know how to use it.

    Thanks a lot

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

    Re: Doubt using RouteSummary() method

    Not certain if I understood correctly, but if you want to show only one route, then you could indeed add code which would remove any old routes before you start adding new ones..

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Re: Doubt using RouteSummary() method

    Thats it, but in my code the old route remain even if i trace a new route. That's why i've sended my code, so anyone can show what am I doing wrong.

    Thanks a lot for the reply

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

    Re: Doubt using RouteSummary() method

    Basically things don't happen magically. Can you point our in where you are removing old content ? I can see you only adding new one with map.objects.add, but never removing anything really.

  5. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Re: Doubt using RouteSummary() method

    i actually add the line "map.objects.remove(mapRoute);" just before the map.objects.add and does not work at all. I've tried the "map.update(-1)" too, but, does not work either. Can you tell my why? Is the currect way to do this ?

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

    Re: Doubt using RouteSummary() method

    map.objects.remove(mapRoute) you would actually use as the mapRoute, the original mapRoute one, not teh one you just constructed, thus of course that does not work. Either try checking whether there is function to clear all objects, or simply loop the objects array and remove them one-by-one (start from last to first, as usual)

  7. #7
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Re: Doubt using RouteSummary() method

    Thanks. Can you clear to me how to do that ?

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

    Re: Doubt using RouteSummary() method

    You could always check the API reference, anyway, you could also search for older discussions, anyway I suppose you could try something like:

    for (i=0; i< map.objects.getLength(); i++) {
    map.objects.remove(map.objects.get(i));
    }

  9. #9
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Re: Doubt using RouteSummary() method

    Yes. You're the man. Works perfectlly.

    Well, after your reply i've checked the API reference to use the method RouteSummary() because i want to show the average travel time to user. But when i try to create an object (var xxx = new nokia.maps.routing.RouteSummary () ) it returns an error. I want to show to the user the value of "baseTime".

    If is not ask too much, can you help me with this one?

    Thanks a lot

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    1

    Re: Doubt using RouteSummary() method

    Thanks a lot

  11. #11
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    289

    Re: Doubt using RouteSummary() method

    Quote Originally Posted by Clog View Post
    Well, after your reply i've checked the API reference to use the method RouteSummary() because i want to show the average travel time to user. But when i try to create an object (var xxx = new nokia.maps.routing.RouteSummary () ) it returns an error. I want to show to the user the value of "baseTime".
    I think you may be after the route.duration rather than RouteSummary() - the travel time can be found in the example here: http://www.developer.nokia.com/Commu...vanced_Routing

    Also since map.objects is an OList it would usually be quicker to call map.objects.clear() than iterating through and removing each item.

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

    Re: Doubt using RouteSummary() method

    Quote Originally Posted by jasfox View Post
    ... map.objects.clear() than iterating through and removing each item.
    Thanks, was looking for that one, but somehow did not find it, so went for the way that knew that is working at least. Anyway, clear() is better in this case..

  13. #13
    Registered User
    Join Date
    Aug 2012
    Posts
    6

    Re: Doubt using RouteSummary() method

    Thanks a lot guys. It's working perfectlly now. One more doubt: When i trace the route, it shows a marker named "A" that is the origin and a marker named "B" that is the destiny. So, is there any way that i can replace this default marker to a custom one (like, my store image)?

    Thanks again.

  14. #14
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    289

    Re: Doubt using RouteSummary() method

    Yes you can. You will need to write your own version of RouteResultSet to do this instead of using the default:

    This question has already been answered here: http://www.developer.nokia.com/Commu...ween-waypoints, and there is sample Code in the thread.

    In your case you will need to update the line below to highlight each Waypoint with Markers, rather than StandardMarkers:
    Code:
    legContainer.objects.add(new nokia.maps.map.StandardMarker(
    						firstroute.waypoints[i].mappedPosition, 
    						{ text: i  + 1 }
    					));

Similar Threads

  1. Doubt in destroyApp() method?
    By jayesh_nokia in forum Mobile Java General
    Replies: 2
    Last Post: 2010-08-09, 20:35
  2. Doubt on the format and downloading method
    By harinrd in forum [Archived] Flash Lite on Nokia Devices
    Replies: 2
    Last Post: 2009-06-24, 19:54
  3. Draw Method ... Basic Doubt
    By Vignesh.M in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-02-13, 12:31
  4. Replies: 0
    Last Post: 2006-01-20, 06:53
  5. passing method as parameter to another method
    By neilcoxhead in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-10, 13:20

Posting Permissions

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