![](/img/trans.png)
[英]Having trouble zooming and centering on users location in MapView in iOS
[英]ios zooming in on users location
嗨,我已經設置了MapKit來顯示用戶位置,但是它正在加載的視圖過於縮小,因此我試圖將其放大到20英里左右的區域。 我嘗試使用其他一些問題的代碼來做到這一點,但是它們似乎都沒有對視圖產生任何影響。 順便說一句,我也試圖看到當前的用戶:緯度和經度,但是在我的float變量中只看到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的新手。
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.