IOS MKMapKit 画圆,设置范围

1.在地图上画圆,用 MKCircle,MKCircleView

MKCircle *circleTargePlace=[MKCircle circleWithCenterCoordinate:hotelKeyWord.coordCurrentUser radius:hotelKeyWord.hotelSiftModel.iRadius];
            [mapViewMian addOverlay:circleTargePlace];

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MKCircle class]]) {
        MKCircleView *_circleView=[[[MKCircleView alloc] initWithCircle:overlay] autorelease];
        _circleView.fillColor =  [UIColor colorWithRed:137/255.0 green:170/255.0 blue:213/255.0 alpha:0.2];
        _circleView.strokeColor = [UIColor colorWithRed:117/255.0 green:161/255.0 blue:220/255.0 alpha:0.8];
        _circleView.lineWidth=2.0;
        return _circleView;
    }
    return nil;
}

2.设置地图中心点和范围有三种方法

2.1  设置中心点和范围,MKCoordinateRegion,如

    MKCoordinateRegion region;
    region.span = MKCoordinateSpanMake(0.5, 0.5);
    region.center = CLLocationCoordinate2DMake(34.0000, 166.0000);
    [mapViewMian setRegion:region animated:YES];

关于 MKCoordinateSpan 的CLLocationDegrees,苹果文档这么解释:

The interesting part of an MKCoordinateRegion structure is the span. The span is analogous to the width and height values of a rectangle but is specified using map coordinates and thus is measured in degrees, minutes, and seconds. One degree of latitude is equivalent to approximately 111 kilometers but longitudinal distances vary with the latitude. At the equator, one degree of longitude is equivalent to approximately 111 kilometers but at the poles this value is zero. If you prefer to specify the span using meters, you can use the MKCoordinateRegionMakeWithDistance to create a region data structure using meter values instead of degrees.


2.2 用  MKCoordinateRegionMakeWithDistance 。通过设置中心点和以米为单位的经纬度,即在中心点,地图显示维度方向的总距离,经度范围的总距离

官方文档:

centerCoordinate

The center point of the new coordinate region.

latitudinalMeters

The amount of north-to-south distance (measured in meters) to use for the span.

longitudinalMeters

The amount of east-to-west distance (measured in meters) to use for the span.


MK_EXTERN MKCoordinateRegion MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2D centerCoordinate, CLLocationDistance latitudinalMeters, CLLocationDistance longitudinalMeters);

讨论:但是这方方法设置的范围,系统会自动调整到合适范围,可能会引起与预期的偏离


2.3 用 MKCoordinateRegionForMapRect ,通过设置 MKMapRect来设置中心和范围。

这个方法适合显示指定区域的,比如在地图上花一个圆,然后显示这个圆的范围,就可以通过 MKCircle 的 boundingMapRect 设置,会显示的比较准确

MKCoordinateRegion MKCoordinateRegionForMapRect(MKMapRect rect)


3.让IOS设备震动

引入 AudioToolbox framework,然后调用以下代码:

AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate) 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值