Commit e15f2a20 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

no message

parent b657a210
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
@property (nonatomic, strong) AMapLocationManager *locationManager; @property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic, strong) MACircle *circle; @property (nonatomic, strong) MKCircle *circle;
@property (nonatomic, strong) SJSlider *slider; @property (nonatomic, strong) SJSlider *slider;
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
_mapView.showsCompass = false; _mapView.showsCompass = false;
// _mapView.zoomLevel = 15.5; // _mapView.zoomLevel = 15.5;
// _mapView.customizeUserLocationAccuracyCircleRepresentation = true; // _mapView.customizeUserLocationAccuracyCircleRepresentation = true;
self.circle = [MACircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500]; self.circle = [MKCircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500];
[self.mapView addOverlay:self.circle]; [self.mapView addOverlay:self.circle];
[AMapServices sharedServices].apiKey = @"501f8a894329f4b57bbfee208a11676f"; [AMapServices sharedServices].apiKey = @"501f8a894329f4b57bbfee208a11676f";
...@@ -130,32 +130,56 @@ ...@@ -130,32 +130,56 @@
self.addressMainTitleLabel.text = _editModel.address; self.addressMainTitleLabel.text = _editModel.address;
self.addressSubTitleLabel.text = _editModel.addressName; self.addressSubTitleLabel.text = _editModel.addressName;
// ZJCustomAnnotation *annotation = [[ZJCustomAnnotation alloc] init];
// annotation.coordinate = self.mapView.centerCoordinate;
// annotation.title = @"北京";
// annotation.subtitle = @"默认显示的为首都北京";
// [self.mapView addAnnotation:annotation];
} }
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{ - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
[mapView removeAnnotations:self.mapView.annotations];
ZJCustomAnnotation *annotation = [[ZJCustomAnnotation alloc] init];
annotation.coordinate = self.mapView.centerCoordinate;
annotation.title = @"北京";
annotation.subtitle = @"默认显示的为首都北京";
[self.mapView addAnnotation:annotation];
} }
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView removeOverlays:self.mapView.overlays];
ZJCustomAnnotation *annotation = [[ZJCustomAnnotation alloc] init]; ZJCustomAnnotation *annotation = [[ZJCustomAnnotation alloc] init];
annotation.coordinate = self.mapView.centerCoordinate; annotation.coordinate = self.mapView.centerCoordinate;
annotation.title = @"北京"; annotation.title = @"北京";
annotation.subtitle = @"默认显示的为首都北京"; annotation.subtitle = @"默认显示的为首都北京";
[self.mapView addAnnotation:annotation]; [self.mapView addAnnotation:annotation];
self.circle = [MKCircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500];
[self.mapView addOverlay:self.circle];
self.location = [[CLLocation alloc] initWithLatitude:mapView.centerCoordinate.latitude longitude:mapView.centerCoordinate.longitude];
[self centerLocation:self.location];
} }
- (void)centerLocation:(CLLocation *)location {
//创建地理编码对象
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
//反地理编码
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//判断是否有错误或者placemarks是否为空
if (error !=nil || placemarks.count==0) {
NSLog(@"%@",error);
return ;
}
CLPlacemark *placemark = [placemarks firstObject];
if (placemark) {
//获取城市
NSString *city = placemark.locality;
if (!city) {
//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
city = placemark.administrativeArea;
}
self.addressMainTitleLabel.text = placemark.name;
self.addressSubTitleLabel.text = [NSString stringWithFormat:@"%@%@%@", placemark.subLocality?:@"", placemark.thoroughfare?:@"", placemark.subThoroughfare?:@""];
}
}];
}
//添加固定 //添加固定
-(void)addPointAnnotation: (CLLocationCoordinate2D )oordinate { -(void)addPointAnnotation: (CLLocationCoordinate2D )oordinate {
self.pointAnnotation = [[MAPointAnnotation alloc] init]; self.pointAnnotation = [[MAPointAnnotation alloc] init];
...@@ -255,7 +279,7 @@ ...@@ -255,7 +279,7 @@
/// Description /// Description
/// @param mapView mapView description /// @param mapView mapView description
- (void)mapViewRegionChanged:(MAMapView *)mapView { - (void)mapViewRegionChanged:(MAMapView *)mapView {
[self.circle setCoordinate:mapView.centerCoordinate]; // [self.circle setCoordinate:mapView.centerCoordinate];
} }
- (void)reverseGeocodeLocation:(CLLocation *)location { - (void)reverseGeocodeLocation:(CLLocation *)location {
...@@ -326,7 +350,8 @@ ...@@ -326,7 +350,8 @@
- (void)sliderDidDrag:(SJSlider *)slider { - (void)sliderDidDrag:(SJSlider *)slider {
NSLog(@"%f", slider.value); NSLog(@"%f", slider.value);
CGFloat ss = (slider.value * 800) + 200; CGFloat ss = (slider.value * 800) + 200;
[self.circle setCircleWithCenterCoordinate:self.mapView.centerCoordinate radius: ss];
// [self.circle setCircleWithCenterCoordinate:self.mapView.centerCoordinate radius: ss];
self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", ss]; self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", ss];
} }
...@@ -334,7 +359,7 @@ ...@@ -334,7 +359,7 @@
sliderDrag = YES; sliderDrag = YES;
/// 缩放级别, [3, 20]// [20, 10] [0, 1] [200 , 1000] /// 缩放级别, [3, 20]// [20, 10] [0, 1] [200 , 1000]
CGFloat ss = (slider.value * 800) + 200; CGFloat ss = (slider.value * 800) + 200;
[self.circle setCircleWithCenterCoordinate:self.mapView.centerCoordinate radius: ss]; // [self.circle setCircleWithCenterCoordinate:self.mapView.centerCoordinate radius: ss];
self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", ss]; self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", ss];
} }
...@@ -358,9 +383,9 @@ ...@@ -358,9 +383,9 @@
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay{ - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay{
if([overlay isKindOfClass:[MKPolyline class]]){ if([overlay isKindOfClass:[MKCircle class]]){
MKPolylineRenderer * circleRenderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay]; MKCircleRenderer * circleRenderer = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleRenderer.lineWidth = 2.f; circleRenderer.lineWidth = 2.f;
circleRenderer.strokeColor= [UIColor colorWithHex:0x4299f9]; circleRenderer.strokeColor= [UIColor colorWithHex:0x4299f9];
circleRenderer.fillColor = [[UIColor colorWithHex:0x4299f9] colorWithAlphaComponent: 0.3]; circleRenderer.fillColor = [[UIColor colorWithHex:0x4299f9] colorWithAlphaComponent: 0.3];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment