After completing the whereami solution as described in ch 5 of the book, I started thinking about how to enhance it. One thing is that the solution always sets the zoom to a fixed distance, e.g. 500m. I was thinking that it would be good to maintain whatever zoom the user has selected. I started playing with mapView:didUpdateUserLocation. I couldn’t figure a way to determine the region distance, but I can access the region span. I use that to create a new region, centered around the updated location.
(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)u
CLLocationCoordinate2D loc = [u coordinate];
// use current span
MKCoordinateSpan span = [mapView region].span;
MKCoordinateRegion region = MKCoordinateRegionMake(loc, span);
// as described in the book
// MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[worldView setRegion:region animated:YES];
This doesn’t quite do what I want to do. First of all, the zoom SHOULD be based on a fixed distance the first time it finds a location. However, after that, as the user zooms in and out, the region should put the new location in the center, but keep the span fixed.
I guess I could use a static variable as a counter so that the method behaves differently the first time the method is called, but I’m thinking there is a more elegant solution. Has anyone done this or have insight into how this could be accomplished?