ios zooming in on users location

280 Views Asked by At

Hi I have set my MapKit up to show users location, but it is loading with a view much too zoomed out, so I am trying to zoom it in to e.g. an area of 20 miles. I tried to do this using code from some other questions but none of them seem to make any difference to the view what so ever. Btw I'm also trying to be able to see the current users: latitude and longitude, but only seeing 0 in my float variable, maybe these are linked?

Here is the code:

- (void)viewDidLoad
{

#ifdef __IPHONE_8_0
    if(IS_OS_8_OR_LATER)
    {
        [self.locationManager requestWhenInUseAuthorization];
    }
#endif

    MKCoordinateSpan span = MKCoordinateSpanMake(20.5982f,0.0001f);
    CLLocationCoordinate2D coordinate = {30, 75};
    MKCoordinateRegion region = {coordinate, span};
    MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
    [self.mapView setRegion:regionThatFits animated:YES];

    self.locationManager.delegate=self;
   [self.locationManager startUpdatingLocation];

    float latitude = self.locationManager.location.coordinate.latitude;
    float longitude = self.locationManager.location.coordinate.longitude;

    [self.mapView.userLocation addObserver:self
                                forKeyPath:@"location"
                                   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
                                   context:NULL];
    self.mapView.showsUserLocation = YES;

Thanks very much for any help you can give with this. I am new to MapKit.

1

There are 1 best solutions below

0
On BEST ANSWER
MKCoordinateSpan span = MKCoordinateSpanMake(30.5982f,0.0001f);
CLLocationCoordinate2D coordinate = {36, 90};
MKCoordinateRegion region = {coordinate, span};
MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
[self.mapView setRegion:regionThatFits animated:YES];