ios放大用户位置

时间:2015-09-04 05:00:05

标签: ios mapkit core-location zooming mkuserlocation

您好我已经将我的MapKit设置为显示用户位置,但它正在加载一个视图太多缩小,所以我试图将其放大到例如面积20英里。 我尝试使用来自其他一些问题的代码来做到这一点,但它们似乎都没有对视图产生任何影响。 顺便说一下,我也试图能够看到当前的用户:纬度和经度,但只在我的浮点变量中看到0,也许这些是链接的?

以下是代码:

- (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;

非常感谢您为此提供的任何帮助。我是MapKit的新手。

1 个答案:

答案 0 :(得分:0)

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];