c# - Windows Phone 8 Map incremental movement based on series of coordinates -
i want have map control on windows phone move between coordinates 1 one. cannot seem the map control wait until animation has finished reaching 1 location before tries move next. have tried few ways wait between movements no avail. here code have far sample app.
public mainpage() { initializecomponent(); map.center = new geocoordinate(54.958879, -7.733027); map.zoomlevel = 13; } private void button_click(object sender, routedeventargs e) { list<location> locations = new list<location>(); (double x = 0, y = 0; y < 10; x+=0.005, y++) { locations.add(new location(54.958879 + x, -7.733027 + x)); locations.add(new location(54.958879 - x, -7.733027 - x)); } foreach (location location in locations) { map.setview(new geocoordinate(location.latitude, location.longitude), 13, mapanimationkind.linear); //i want app wait until view has finished moving before moving again } } class location { public double latitude { get; set; } public double longitude { get; set; } public location(double lat, double lon) { latitude = lat; longitude = lon; } }
i sure missing simple. can solve problem?
i use dispatchertimer
, on tick
event, iterate next coord , call setview
.
for example:
private dispatchertimer timer; private int index = 0; list<location> locations = new list<location>(); public mainpage() { initializecomponent(); timer = new system.windows.threading.dispatchertimer { interval = timespan.fromseconds(1) // todo: interval }; timer.tick += timer_tick; } private void button_click(object sender, routedeventargs e) { locations.clear(); (double x = 0, y = 0; y < 10; x+=0.005, y++) { locations.add(new location(54.958879 + x, -7.733027 + x)); locations.add(new location(54.958879 - x, -7.733027 - x)); } timer.start(); } void timer_tick(object sender, eventargs e) { var item = locations[index]; map.setview(new geocoordinate(item.latitude, item.longitude), 13, mapanimationkind.linear); if(index >= locations.count) timer.stop(); else index++; }
Comments
Post a Comment