我有我的應用程序的用戶位置,但我將如何刪除當前用戶位置的註釋?我是否必須獲取用戶位置的長整數&,然後刪除註釋?或者我會怎麼做?iOS- MKMapKit-我將如何刪除用戶位置的註釋?
2
A
回答
2
- 首先導入必要的框架(CoreLocation和MapKit)。
- 然後創建目標C NSObject類註釋
設置其.H:
#import <Foundation/Foundation.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface Annotation : NSObject <MKAnnotation> @property (nonatomic) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subtitle; @end
安裝其的.m:
#import "Annotation.h" @implementation Annotation @synthesize coordinate, title, subtitle; @end
設置
viewDidLoad
if ([CLLocationManager locationServicesEnabled]) { locationManager = [[CLLocationManager alloc] init]; [locationManager setDelegate:self]; [locationManager setDesiredAccuracy: kCLLocationAccuracyBestForNavigation]; [locationManager startUpdatingLocation]; } self.mapView.delegate = self;
設置的
didUpdateToLocation
// IMPORT ANNOTATION - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [locationManager stopUpdatingLocation]; double miles = 3.10686; double scalingFactor = ABS((cos(2 * M_PI * newLocation.coordinate.latitude/360.0))); MKCoordinateSpan span; span.latitudeDelta = miles/69.0; span.longitudeDelta = miles/(scalingFactor * 69.0); MKCoordinateRegion region; region.span = span; region.center = newLocation.coordinate; [self.mapView setRegion:region animated:YES]; Annotation *annot = [[Annotation alloc] init]; annot.coordinate = newLocation.coordinate; [self.mapView addAnnotation:annot]; }
0
最簡單的方法是設置showsUserLocation
到YES
您MKMapView
並在MKMapViewDelegate
實施
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, MKCoordinateSpanMake(0.01, 0.01));
[mapView setRegion:region animated:NO];
}
擁有地圖視圖移動當用戶的位置被發現時的那個位置。
這將在地圖視圖上顯示用戶位置上的藍色圓點,就像地圖應用一樣。
相關問題
- 1. iOS - MKMapKit,顯示註釋中用戶位置的地址
- 2. 與位置的iOS MKMapKit初始化不是用戶位置
- 3. 如何從MKMapView中除去用戶位置註釋以外的所有註釋?
- 4. 的iOS 8 MkMapKit無法獲取用戶位置
- 5. 如何在Mapbox中禁用用戶位置註釋的標註?
- 6. 如何刪除XML註釋
- 7. 在顯示特定位置MKMapkit後縮放到用戶位置?
- 8. iOS MapKit用戶位置註釋的Z索引
- 9. iOS:我將如何在用戶的位置放置地標?
- 10. 註釋引腳用作用戶位置
- 11. 用戶位置註釋的自定義註釋
- 12. SKMapView(Skobbler)上沒有顯示用戶當前位置註釋 - iOS
- 13. MapKit註釋和用戶位置
- 14. 更改MKMapView用戶位置註釋
- 15. MKMapView自定義用戶位置註釋
- 16. 用戶位置氣泡註釋更改爲自定義註釋
- 17. 如何在Swift中選擇用戶的位置註釋
- 18. iOS 11 PDFKit不更新註釋位置
- 19. 如何刪除JDefinedClass上的註釋
- 20. 如何刪除剛添加的註釋?
- 21. 如何動畫剛刪除的註釋?
- 22. 刪除當前位置上的註釋(Pin)
- 23. 刪除註釋iTextSharp
- 24. 刪除SQL註釋
- 25. 獲得5個最近註釋MKMapKit
- 26. 使用biomaRt註釋位置
- 27. 如何刪除XML註釋沒有XSLT
- 28. 如何僅刪除註釋語法?
- 29. 如何刪除某些註釋銷
- 30. 如何刪除HTML註釋在PHP