我正在寻找自定义的MKMapView userLocation注释,以绘制一个像官方地图应用程序的标题箭头。
我正尝试在viewForAnnotation中做到这一点:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]) {
}
}但是我找不到下一步要做什么来获取UserLocation的视图并对其进行自定义。
非常感谢。
发布于 2011-03-10 04:14:15
默认用户位置标记(至少在SDK4.2中)的类是MKUserLocationView,但它不是公共的,因此您无法创建一个实例进行修改而不冒被应用程序商店拒绝的风险。相反,您必须创建自己的MKAnnotationView (或MKAnnotationView的子类)。
发布于 2013-03-05 03:55:18
我创建了MKUserLocationView的可定制复制品SVPulsingAnnotationView。

您可以像任何其他MKAnnotationView一样实例化它
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if([annotation isKindOfClass:[MyAnnotationClass class]]) {
static NSString *identifier = @"currentLocation";
SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(pulsingView == nil) {
pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pulsingView.annotationColor = [UIColor colorWithRed:0.678431 green:0 blue:0 alpha:1];
}
pulsingView.canShowCallout = YES;
return pulsingView;
}
return nil;
}发布于 2017-08-28 20:57:30
导入UIKit导入MapKit导入CoreLocation
类secondViewController: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate{
@IBOutlet var mapview: MKMapView!// var locationmanager = CLLocationManager()
let locationManager = CLLocationManager()
var currentLocation: CLLocation!/*公共函数管理器(_locationManager: CLLocationManager,didUpdateLocations位置: CLLocation) {
let location = locations[0]
let span = MKCoordinateSpanMake(0.1, 0.1)
let my = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
print(my)
let region = MKCoordinateRegionMake(my, span)
mapview.setRegion(region, animated: true)
self.mapview.showsUserLocation = true
}*/
override func viewDidLoad() {
super.viewDidLoad()
/* mapview.mapType = MKMapType.standard
locationmanager.delegate = self
locationmanager.desiredAccuracy = kCLLocationAccuracyBest
locationmanager.requestWhenInUseAuthorization()
/* isAuthorizedtoGetUserLocation()
if CLLocationManager.locationServicesEnabled() {
locationmanager.delegate = self
locationmanager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
}*/
locationmanager.startUpdatingLocation()*/https://stackoverflow.com/questions/5250440
复制相似问题