iOS中的地图属性设置以及位置的管理

上次只是大概说了一下显示地图的几种方法,以及如何设置地图的一些属性,今天跟大家分享的事如何在地图上进行位置注解以及进行位置管理。

//    完成位置反编码
    CLGeocoder *geocoder = [[CLGeocoder alloc ]init];
    CLLocation *location = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        if (nil != error) {
            NSLog(@"error info is %@",error);
        }
        for (CLPlacemark *placeMark in placemarks) {
            NSLog(@"%@,%@,%@,%@,%@,%@,%@,%@,%@",placeMark.country,placeMark.areasOfInterest,placeMark.ocean,placeMark.ISOcountryCode,placeMark.inlandWater,placeMark.locality,placeMark.postalCode,placeMark.administrativeArea,placeMark.subLocality);
        }
    }];
显示位置注解:这里用硬编码方式示例

    MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc]init];
    pointAnnotation.coordinate = coordinate;
    pointAnnotation.title = @"你好";
    pointAnnotation.subtitle = @"世界";
    [self.mapView addAnnotation:pointAnnotation];
使用 MKMapViewDelegate来实现地图的位置信息以及大头针的显示

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *indentify = @"indentify";
    MKPinAnnotationView *pinAnnotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:indentify];
    if (nil == pinAnnotationView) {
        pinAnnotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:indentify];
    }
    pinAnnotationView.image = [UIImage imageNamed:@"icon_nav_start"];
    
    UIImageView *imageVew = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    imageVew.image = [UIImage imageNamed:@"Icon"];
    pinAnnotationView.leftCalloutAccessoryView = imageVew;
    
    pinAnnotationView.animatesDrop = YES;
    pinAnnotationView.pinColor = MKPinAnnotationColorPurple;
    pinAnnotationView.canShowCallout = YES;
    
    return pinAnnotationView;
}
当然在这之前还是要遵循CLLocationManagerDelegate,MKMapViewDelegate协议的
设置好后,运行即可看到大头针的位置显示视图了。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值