[英]How to zoom into user current location?
當應用程序在MapKit中啟動時,我想放大用戶的當前位置。 這是我的代碼(在viewDidLoad函數中):
Locate=[[CLLocationManager alloc]init];
Locate.delegate=self;
Locate.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
Locate.distanceFilter=kCLDistanceFilterNone;
[Locate startUpdatingLocation];
[super viewDidLoad];
//Region
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;
//Span
MKCoordinateSpan span;
span.latitudeDelta=0.3f;
span.longitudeDelta=0.3f;
//Set Region
myRegion.center=center;
myRegion.span=span;
[_MyMap setRegion:myRegion animated:YES];
我還用與前面相同的代碼實現了didUpdateLocation
函數。 問題是,當用戶位置更改時(用戶移動時),屏幕會放大他的位置,但我無法移動屏幕,如果嘗試移動它,則會立即返回用戶位置,因此我無法看到整個地圖。
對於縮放,你必須改變區域值映射器件中心和span.once看到這樣一個MapView的縮放
在我的情況下,當我單擊特定按鈕時,我已使用此按鈕移動地圖。
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];
我通過添加touchesMoved函數解決了此問題,並且停止更新此函數中的Location。 解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.