Map.View addRoute not working

You must Login before you can answer or comment on any questions.

Hi, I'm using a module called de.codewire.google.directions. basically it transforms an address into an abstract object to be used by addRoute() method for the Map view.

I tried the demo, and it worked, afterwards I tried to implement it in my app and it seems to work, because the resulting object is the right one

{name: "name", color: "#FF0000", points: [points], width: 2}
but, the route is not traced on the map view. it doesn't show up.

here is the code:

directions: function ()
    {
        Titanium.Geolocation.getCurrentPosition(function(e) {
 
            var s = e.coords; // example {latitude: 000.000, longitute: 000.000}
            var dx = "W Sahara Avenue, Las Vegas Nevada USA"; //location for test purposes
 
            Directions.map.getRoute({   //Directions is the class, map is the module
                origin : s, 
                destination : dx,
                color : 'blue',
                mode : Directions.map.travelModes.driving,
                name : 'route',
                width : 5, 
                callback : function(response) {
                    if(response.status == 'OK')   //the response IS OK
                    {
                        Directions.mv.setRegion({       //a pointer to the MapView object
                            latitude : response.route.points[0].latitude,
                            longitude : response.route.points[0].longitude,
                            longitudeDelta : 0.04,
                            latitudeDelta : 0.04
                        });
 
                        Directions.mv.addRoute(response.route);
                    }
                    else
                    {
                        alert(response.msg);
                    }
                }
            });
        });
    }
Do I have to add the Map view to another view or window and show it before executing this function?

this is the how the mapView is created:

Directions.mv = Titanium.Map.createView({
            top:0,
            height: 400,
            userLocation: false,
            mapType: Titanium.Map.HYBRID_TYPE,
            regionFit: true
        });
 
    Directions.map = require("de.codewire.google.directions"); 
 
        Directions.add(Directions.mv); //equivalent to Titanium.UI.View.add()
 
    Directions.directions();    //the call to the function above is made at this point

— asked 11 months ago by Ani Sinanaj
3 Comments
  • Hi Ani,

    Did you see map or not?.

    — commented 11 months ago by Nitin Chavda

  • Hi Nitin

    Yes, the map is shown, and the setRegion also works that's the oddest part. I call to functions on the same object - setRegion and addRoute - the first works and the second doesn't

    — commented 11 months ago by Ani Sinanaj

  • Hi Ani,

    Then try to debug your application that help you.

    — commented 11 months ago by Nitin Chavda

1 Answer

Accepted Answer

What I can see so far your code looks well. Make sure your route has a unique name, Ti uses it as an id to acces them. If you want you can email us timodules@codewire.de with more relevant code.

— answered 11 months ago by Alexander Bauer
answer permalink
1 Comment
  • I found a temporary fix by first making getting the route points from using your module and on its success I create the map view, add the route to the map and that add the whole thing to the main window. What I think happened is that everything worked fine but the route remained below the mapView (zIndex).

    — commented 11 months ago by Ani Sinanaj

Your Answer

This question has been locked and cannot accept new answers.