IOS MKMapKit 画圆,设置范围
2013-06-26 21:32
423 查看
1.在地图上画圆,用 MKCircle,MKCircleView
2.设置地图中心点和范围有三种方法
2.1 设置中心点和范围,MKCoordinateRegion,如
关于 MKCoordinateSpan 的CLLocationDegrees,苹果文档这么解释:
The interesting part of an
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
create a region data structure using meter values instead of degrees.
2.2 用 MKCoordinateRegionMakeWithDistance
。通过设置中心点和以米为单位的经纬度,即在中心点,地图显示维度方向的总距离,经度范围的总距离
官方文档:
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)
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
MKCoordinateRegionstructure
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
MKCoordinateRegionMakeWithDistanceto
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. |
CLLocationDistance latitudinalMeters, CLLocationDistance longitudinalMeters);
讨论:但是这方方法设置的范围,系统会自动调整到合适范围,可能会引起与预期的偏离
2.3 用 MKCoordinateRegionForMapRect
,通过设置 MKMapRect来设置中心和范围。
这个方法适合显示指定区域的,比如在地图上花一个圆,然后显示这个圆的范围,就可以通过 MKCircle
的 boundingMapRect 设置,会显示的比较准确
MKCoordinateRegion MKCoordinateRegionForMapRect(MKMapRect rect)
3.让IOS设备震动
引入 AudioToolbox framework,然后调用以下代码:
AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate)
相关文章推荐
- iOS 原生地图(MapKit、MKMapView)轨迹渐变
- 设置tableview的滚动范围--iOS开发系列---项目中成长的知识三
- iOS 设置UILabel中的text指定范围的字体颜色
- iOS UITableView(十四) 设置TbleviewController的滚动范围
- iOS 百度地图 设置显示区域 中心点和范围
- ios TableView那些事(二十八)UITableViewController 设置滑动范围
- iOS 设置searchBar下面的范围选择框
- iOS 百度地图 设置显示区域 中心点和范围
- ios iphone UISearchBar 使用 及 怎么设置searchBar下面的范围选择框
- iOS APP设置启动图片LaunchImages
- iOS开发笔记--将视图或者按钮设置为圆形
- iOS开发之同一应用设置不同图标和名称
- ios-AppDelegate中设置根视图控制器
- iOS 11开发教程(十九)iOS11应用视图美化按钮之设置按钮的外观
- 【Cocos2d-x】 关于IOS设置竖屏后,运行会报错的解决方法
- iOS按钮防止连续点击 可以自己设置响应间隔
- iOS 偏好设置NSUserDefaults
- “iOS 推送通知”详解:从创建到设置到运行
- opencv-ios开发笔记12 svm参数设置和自动优选