0

I have a function in my view controller with a mapkit that is called when the location changes. I would like set to the map view so that is is centered around the current location and moves with it as it updates.

It works in a sense i.e it tracks along, however it is always zoomed in really far. If I zoom out it snaps back to where it was when it calls the update again after getting a new location.

in from params CLLocation *loc
bool first = TRUE;
if(first){
        first=FALSE; // bit of a bodge...if i set this to false it will track the update possition but not at the desired "zoom" its look far to close.
        CLLocation *loc = [[CLLocation alloc] initWithLatitude:54.976619 longitude:-1.613118];//newcastle city center.
        CLLocationDegrees spanLat = 1000;
        CLLocationDegrees spanLng = 1000;  
        userLocation = MKCoordinateRegionMakeWithDistance(loc.coordinate, spanLat, spanLng);
        [mapview setRegion:userLocation animated:TRUE];
    }else {
        CLLocationDegrees spanLat = [mapview region].span.latitudeDelta;//  keep the originals? DOESN'T WORK!!
        CLLocationDegrees spanLng = [mapview region].span.longitudeDelta;//  
        userLocation = MKCoordinateRegionMakeWithDistance(loc.coordinate, spanLat, spanLng);
        [mapview setRegion:userLocation animated:TRUE];
    } 
4

1 回答 1

2

Just keep setting the center coordinate and don't set the region.

By the way, you do know that you don't need any of that code, right? You can just tell the mapview to track the device's current location. See my book for an example:

http://www.apeth.com/iOSBook/ch34.html#_map_kit_and_current_location

于 2013-03-29T22:29:24.323 回答