Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iPhone route only displayed when user moves the map.

Hi

Does anybody know the problem? The map is displayed. The annotations are also correctly shown. But the user can't see the route. When he starts moving the map, the route appears.

mapView = Titanium.Map.createView({
       mapType: Titanium.Map.STANDARD_TYPE,
       region: {latitude: 47.95, longitude: 16.29,
                 latitudeDelta:0.1, longitudeDelta:0.1},
       animate:true,
       regionFit:true,
       userLocation:true,
       annotations: objects
});
var routeNeu = {
      name:"route",
      points: points,
      color:"blue",
      width:4
};
mapView.addRoute(routeNeu);
win.add(mapView);

Thanks for your help!

Felix

EDIT: If I make a setTimout for about 2 seconds and then move the map to the correct point (initialize with {}), it works… but I don't think, that's a good solution.

— asked September 18th 2010 by Felix Krause
  • display
  • iphone
  • map
  • route
0 Comments

3 Answers

  • Accepted Answer

    Here is how I fixed it( somehow like you did )

    http://developer.appcelerator.com/question/60131/mapview-addroute-bug

    — answered September 19th 2010 by Dan Tamas
    permalink
    1 Comment
    • Thank you so much for your help. Works great!
      Do you know, how to let the map scroll and zoom automatically so that the whole route is automatically displayed?
      Thanks
      Felix

      — commented September 21st 2010 by Felix Krause
  • Nobody has got a solution?

    — answered September 19th 2010 by Felix Krause
    permalink
    0 Comments
  • You set the region of the map in such a way it contains all the points that defines the route and some margins.
    Hee is a code I use, but it's not 100% Titanium( I use my own wrapper ), but will give you an idea

        var lons = [],lats=[];
    
                for ( var v in venues ) {
    
      // some other code here
                    });
    
                    lons.push(venues[v].longitude);
                    lats.push(venues[v].latitude);
    
                //    venues_map.el.addAnnotation(v_pin.el);
                }
    
                var venues_region = {
                    latitude:array_min(lats)+(array_max(lats) - array_min(lats))/2, 
                    longitude:array_min(lons)+(array_max(lons) - array_min(lons))/2,  
                    latitudeDelta:(array_max(lats) - array_min(lats))+0.02,
                    longitudeDelta:(array_max(lons) - array_min(lons))+0.02
                };
    
                venues_map.set('region',venues_region);
    

    let me know

    — answered September 22nd 2010 by Dan Tamas
    permalink
    1 Comment
    • Thank you so much! I just didn't know the sense of the latitudeDelta/lngDeltag compared to the setting zoom.
      Just developed my own method.
      If someone needs it:

      var currLat, currLng;
         var latMax, latMin, lngMax, lngMin;
         for (var i = 0; i < points.length; i++) {
            currLat = parseFloat(points[i].latitude);
            currLng = parseFloat(points[i].longitude);
            if (!latMax || currLat > latMax) latMax = currLat;
            if (!latMin || currLat < latMin) latMin = currLat;
            if (!lngMax || currLng > lngMax) lngMax = currLng;
            if (!lngMin || currLng < lngMin) lngMin = currLng;
         }
         mapLat = (latMax + latMin) / 2;
         mapLng = (lngMax + lngMin) / 2;
         mapLatDelta = latMax - latMin + 0.01;
         mapLngDelta = lngMax - lngMin + 0.01;
      

      Thanks Daniel!! Works perfectly!

      — commented September 22nd 2010 by Felix Krause
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.