What I am trying to do is, when you press a button, the app auto pan and zoom to current location. Then I can pan the map to other place, and when I press that button again, it will still bring me to my current location (auto pan and zoom).
My problem is, when I first press the button, it works as i expected. Then I move to other place on the map, and when i press the button again, it does not auto pan and zoom to my current location.
Code is below:
- (void)viewDidLoad {
[super viewDidLoad];
// add map layers
... ...
self.mapView.locationDisplay.autoPanMode = AGSLocationDisplayAutoPanModeCompassNavigation;
self.mapView.locationDisplay.navigationPointHeightFactor = 0.5;
[self.mapView.locationDisplay addObserver:self forKeyPath:@location options:NSKeyValueObservingOptionNew context:NULL];
}
- (IBAction)showCurrentLocation:(id)sender {
[self.mapView.locationDisplay startDataSource];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqual:@location]) {
// creating graphics on current location
... ...
[self.mapView.locationDisplay stopDataSource];
}
}