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
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… ;)
-
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 :)
-
ok, try this:
I set the map with this properties, center is the object for region.
Pay attention to height - is 301top: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);