Titanium Community Questions & Answer Archive

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

Add points to an exisiting route -> route invisble. Short move from user required

Hello

I want to track the user's location on a map. So I use

var route = {
   name:"your route",
   points:points,
   color:"blue",
  width:4
};
mapView.addRoute(route);

On every location change I just want to add the current location of the user.

route.points.push({latitude:e.coords.latitude,longitude:e.coords.longitude});

The content of the array is correct -> the new point is added properly, but the user can't see the route. He has to move the map shortly to view the route. There is a possibility to set regionFit to false and after 500ms again to true, but I don't think, it's a good solution, because the map automatically zooms and old iPhones will take more time than the iPhone 4.

Would be great, if someone knows how to fix it!

Thanks

Felix

— asked September 24th 2010 by Felix Krause
  • addroute
  • current
  • invisible
  • iphone
  • location
  • maps
  • push
  • route
  • track
0 Comments

3 Answers

  • Here was my solution:

    inline code

    setTimeout(function() {
      var newRegion = mapView.region;
      newRegion.latitude += 0.00001;
      mapView.region = newRegion;
    }, 500);
    

    for some reason when I tried to just do mapView.region.latitude += 0.00001 it didn't work, didn't spend any time debugging though, so much to do… ;)

    — answered February 3rd 2011 by Hannah Byrne
    permalink
    0 Comments
  • try this:

    • set the regionFit to true
    • set an initial region ( lat,lon,deltaLat,deltaLon );
    • set the route
    • set a new region( lat,lon,deltaLat+0.001,deltaLon+0.001 );

    not tested, but please let me know as I might need it too :)

    — answered September 24th 2010 by Dan Tamas
    permalink
    2 Comments
    • Hi
      Thanks for answering my question.
      I tried it in this way:

      mapView.region = {latitude:e.coords.latitude, longitude:e.coords.longitude, latitudeDelta:0.05, longitudeDelta:0.05};
      mapView.removeRoute(route);
      route.points.push({latitude:e.coords.latitude,longitude:e.coords.longitude});
      mapView.addRoute(route);
      mapView.region = {latitude:e.coords.latitude, longitude:e.coords.longitude, latitudeDelta:0.051, longitudeDelta:0.051};
      

      If I don't use remove and addRoute there won't display the route even if the user moves the map.

      Thanks

      Felix

      — commented September 24th 2010 by Felix Krause
    • But the map won't display properly… You have to move the map…

      If I use this code:

      mapView.region = {latitude:e.coords.latitude, longitude:e.coords.longitude, latitudeDelta:0.05, longitudeDelta:0.05};
            mapView.removeRoute(route);
            route.points.push({latitude:e.coords.latitude,longitude:e.coords.longitude});
            mapView.addRoute(route);
            setTimeout(function() {
               mapView.region = {latitude:e.coords.latitude, longitude:e.coords.longitude, latitudeDelta:0.051, longitudeDelta:0.051};
            }, 400);
      

      it works sometimes.. but again, there is a timeout… so on old phones it won't work properly.

      Thanks
      Felix

      — commented September 24th 2010 by Felix Krause
  • ok, try this:

    I set the map with this properties, center is the object for region.
    Pay attention to height - is 301

    
        top:60,
        width:300,
        height:301,
        mapType: Titanium.Map.STANDARD_TYPE,
        animate:false,
        userLocation:false,
        annotations:[dest,start],
        region:center
    

    then I change the height of the map with 1px only, it will force a redraw and the user doesn't even feel. One drawback would be the regionChanged event gets triggered, but if you need with a flag you can solve it easily.
    I'm testing on a 3GS and works just fine( no delays ).

        event_map.addRoute(result.route);    
    
        event_map.inject(win);
    
        setTimeout( function() {
            event_map.height =  300;    
        }, 500);
    
    — answered September 27th 2010 by Dan Tamas
    permalink
    0 Comments
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.