首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKMapView自定义UserLocation注解

MKMapView自定义UserLocation注解
EN

Stack Overflow用户
提问于 2011-03-10 02:31:40
回答 3查看 3.2K关注 0票数 3

我正在寻找自定义的MKMapView userLocation注释,以绘制一个像官方地图应用程序的标题箭头。

我正尝试在viewForAnnotation中做到这一点:

代码语言:javascript
复制
 - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
 {

    if ([annotation isKindOfClass:[MKUserLocation class]]) {

    }
 }

但是我找不到下一步要做什么来获取UserLocation的视图并对其进行自定义。

非常感谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-03-10 04:14:15

默认用户位置标记(至少在SDK4.2中)的类是MKUserLocationView,但它不是公共的,因此您无法创建一个实例进行修改而不冒被应用程序商店拒绝的风险。相反,您必须创建自己的MKAnnotationView (或MKAnnotationView的子类)。

票数 5
EN

Stack Overflow用户

发布于 2013-03-05 03:55:18

我创建了MKUserLocationView的可定制复制品SVPulsingAnnotationView

您可以像任何其他MKAnnotationView一样实例化它

代码语言:javascript
复制
- (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;
}
票数 6
EN

Stack Overflow用户

发布于 2017-08-28 20:57:30

导入UIKit导入MapKit导入CoreLocation

类secondViewController: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate{

代码语言:javascript
复制
@IBOutlet var mapview: MKMapView!

// var locationmanager = CLLocationManager()

代码语言:javascript
复制
let locationManager = CLLocationManager()
var currentLocation: CLLocation!

/*公共函数管理器(_locationManager: CLLocationManager,didUpdateLocations位置: CLLocation) {

代码语言:javascript
复制
    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()*/
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5250440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档