作者:手机用户2502916627 | 来源:互联网 | 2023-05-18 09:29
1.在地图上画圆,用MKCircle,MKCircleViewMKCircle*circleTargePlace[MKCirclecircleWithCenterCoordinate:hote
1.在地图上画圆,用 MKCircle,MKCircleView
MKCircle *circleTargePlace=[MKCircle circleWithCenterCoordinate:hotelKeyWord.coordCurrentUser radius:hotelKeyWord.hotelSiftModel.iRadius];
[mapViewMian addOverlay:circleTargePlace];
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )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)