0
我有三個視圖是ViewController視圖的子視圖。三個標籤切換其各自的知名度。在「我附近」功能中,我只想顯示10英里範圍內的用戶當前位置內的項目。MKMapView放大到錯誤的地區
在ViewController.h
@property (weak, nonatomic) IBOutlet MKMapView *nearMeMapView;
@property (strong, nonatomic) CLLocationManager *locationManager;
在ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager.delegate = self;
self.nearMeMapView.delegate = self;
}
- (IBAction)nearMeTap:(id)sender
{
self.nearMeMapView.hidden = NO;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager startUpdatingLocation];
NSLog(@"near me tapped")
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = newLocation.coordinate.latitude;
zoomLocation.longitude= newLocation.coordinate.latitude;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 10*METERS_PER_MILE, 10*METERS_PER_MILE);
[self.nearMeMapView setRegion:viewRegion animated:YES];
}
無論如何,問題是被正確地檢測到所述設備的該位置,但MapView的縮放和動畫完全錯誤的位置。
'zoomLocation.longitude'設置爲緯度而不是經度。 – Anna