0

嗨,我已经将我的 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 的新手。

4

1 回答 1

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];
于 2015-09-04T06:36:30.363 回答