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

no message

parent dd17385f
No preview for this file type
......@@ -17,11 +17,15 @@
#import <CoreLocation/CoreLocation.h>
#import "ZJUserInfoManager.h"
@interface ZJLocationRemindSelectController ()<MAMapViewDelegate, SJSliderDelegate, AMapSearchDelegate>{
#import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h"
#import "ZJMapPinchGestureRecognizer.h"
@interface ZJLocationRemindSelectController ()<MAMapViewDelegate, SJSliderDelegate, AMapSearchDelegate, MKMapViewDelegate>{
BOOL sliderDrag;
}
@property (nonatomic, strong) MAMapView *mapView;
@property (nonatomic, strong) MKMapView *mapView;
@property (weak, nonatomic) IBOutlet UIView *sliderContainerView;
@property (weak, nonatomic) IBOutlet UILabel *addressMainTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressSubTitleLabel;
......@@ -38,7 +42,7 @@
@property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic, strong) MACircle *circle;
@property (nonatomic, strong) MKCircle *circle;
@property (nonatomic, strong) SJSlider *slider;
......@@ -77,34 +81,29 @@
- (void)setupMapViewAndUI {
///初始化地图
self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
// if ([ZJUserInfoManager CNLanguage]) {
// self.mapView.mapLanguage = @0;
// }else{
// self.mapView.mapLanguage = @1;
// }
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
///把地图添加至view
[self.view addSubview: _mapView];
[self.view sendSubviewToBack:_mapView];
self.mapView.mapType = 0;
_mapView.showsWorldMap = @YES;
[self.mapView performSelector:@selector(setShowsWorldMap:) withObject:@(YES)];
if ([ZJUserInfoManager CNLanguage]) {
self.mapView.mapLanguage = @0;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(0)];
}else{
self.mapView.mapLanguage = @1;
[self.mapView performSelector:NSSelectorFromString(@"setMapLanguage:") withObject:@(1)];
}
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView.showsUserLocation = false;
_mapView.delegate = self;
_mapView.showsScale = false;
_mapView.showsCompass = false;
_mapView.zoomLevel = 15.5;
_mapView.customizeUserLocationAccuracyCircleRepresentation = true;
self.circle = [MACircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500];
// _mapView.zoomLevel = 15.5;
// _mapView.customizeUserLocationAccuracyCircleRepresentation = true;
self.circle = [MKCircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500];
[self.mapView addOverlay:self.circle];
[AMapServices sharedServices].apiKey = @"501f8a894329f4b57bbfee208a11676f";
SJSlider *slider = ({
SJSlider *slider = [SJSlider new];
[self.view addSubview:slider];
......@@ -124,7 +123,7 @@
[slider mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.sliderContainerView);
}];
self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", self.mapView.metersPerPointForCurrentZoom * 20 + 200.0];
// self.distanceTipLabel.text = [NSString stringWithFormat:@"%0.fm", self.mapView.metersPerPointForCurrentZoom * 20 + 200.0];
if (_editModel) {
self.distanceTipLabel.text = [NSString stringWithFormat:@"%0dm", _editModel.radius];
}
......@@ -132,8 +131,68 @@
self.addressMainTitleLabel.text = _editModel.address;
self.addressSubTitleLabel.text = _editModel.addressName;
CLLocationCoordinate2D centerLocationCoordinate = [self.mapView convertPoint:self.mapView.center toCoordinateFromView:self.mapView];
[self.mapView setRegion:MKCoordinateRegionMakeWithDistance( centerLocationCoordinate, 10000, 10000) animated:false];
[self.mapView addGestureRecognizer:[[ZJMapPinchGestureRecognizer alloc] initWithMapView:self.mapView]];
}
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(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];
annotation.coordinate = self.mapView.centerCoordinate;
annotation.title = @"北京";
annotation.subtitle = @"默认显示的为首都北京";
[self.mapView addAnnotation:annotation];
self.circle = [MKCircle circleWithCenterCoordinate:self.mapView.centerCoordinate radius:500];
[self.mapView addOverlay:self.circle];
//
// CLLocationCoordinate2D center = mapView.region.center;
// //设置跨度为当前地图范围的跨度 * 比例系数
// MKCoordinateSpan span = MKCoordinateSpanMake(mapView.region.span.latitudeDelta * 2, mapView.region.span.longitudeDelta * 2);
// [mapView setRegion:MKCoordinateRegionMake(center, span) animated:NO];
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 {
self.pointAnnotation = [[MAPointAnnotation alloc] init];
......@@ -188,6 +247,7 @@
// [self.searchApi AMapReGoecodeSearch: self.searchRequest];
self.location = [[CLLocation alloc] initWithLatitude:poi.location.latitude longitude:poi.location.longitude];
[self reverseGeocodeLocation: self.location];
};
[self.navigationController pushViewController:searchVC animated:true];
}
......@@ -197,7 +257,7 @@
ZJFriendLocationRemindModel *model = [[ZJFriendLocationRemindModel alloc] init];
model.address = self.addressMainTitleLabel.text;
model.addressName = self.addressSubTitleLabel.text;
model.radius = self.mapView.metersPerPointForCurrentZoom * 20 + 200.0;
// model.radius = self.mapView.metersPerPointForCurrentZoom * 20 + 200.0;
model.lat = [self.location coordinate].latitude;
model.lon = [self.location coordinate].longitude;
model.remark = self.remarkString;
......@@ -232,7 +292,7 @@
/// Description
/// @param mapView mapView description
- (void)mapViewRegionChanged:(MAMapView *)mapView {
[self.circle setCoordinate:mapView.centerCoordinate];
// [self.circle setCoordinate:mapView.centerCoordinate];
}
- (void)reverseGeocodeLocation:(CLLocation *)location {
......@@ -252,7 +312,7 @@
}
self.addressMainTitleLabel.text = placemark.name;
self.addressSubTitleLabel.text = [NSString stringWithFormat:@"%@%@%@", placemark.subLocality?:@"", placemark.thoroughfare?:@"", placemark.subThoroughfare?:@""];
self.addressSubTitleLabel.text = [NSString stringWithFormat:@"%@%@%@", placemark.subLocality, placemark.thoroughfare, placemark.subThoroughfare?:@""];
// 市
NSLog(@"locality,%@",placemark.addressDictionary);
......@@ -260,7 +320,6 @@
NSLog(@"No results were returned.");
} else if (error != nil){
NSLog(@"An error occurred = %@", error);
[self reverseGeocodeLocation:self.location];
}
}];
}
......@@ -304,7 +363,8 @@
- (void)sliderDidDrag:(SJSlider *)slider {
NSLog(@"%f", slider.value);
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];
}
......@@ -312,27 +372,62 @@
sliderDrag = YES;
/// 缩放级别, [3, 20]// [20, 10] [0, 1] [200 , 1000]
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];
}
/// 设置的样式
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
if([overlay isKindOfClass:[MACircle class]]) {
///// 设置的样式
//- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
//{
// if([overlay isKindOfClass:[MACircle class]]) {
//
// MACircleRenderer *circleRenderer = [[MACircleRenderer alloc] initWithCircle:(MACircle *)overlay];
//
// circleRenderer.lineWidth = 2.f;
//
// circleRenderer.strokeColor= [UIColor colorWithHex:0x4299f9];
//
// circleRenderer.fillColor = [[UIColor colorWithHex:0x4299f9] colorWithAlphaComponent: 0.3];
//
// return circleRenderer;
// }
// return nil;
//}
MACircleRenderer *circleRenderer = [[MACircleRenderer alloc] initWithCircle:(MACircle *)overlay];
circleRenderer.lineWidth = 2.f;
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay{
if([overlay isKindOfClass:[MKCircle class]]){
MKCircleRenderer * circleRenderer = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleRenderer.lineWidth = 2.f;
circleRenderer.strokeColor= [UIColor colorWithHex:0x4299f9];
circleRenderer.fillColor = [[UIColor colorWithHex:0x4299f9] colorWithAlphaComponent: 0.3];
return circleRenderer;
}
return nil;
}
//创建大头针时调用
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
//如果返回空,代表大头针样式交由系统去管理
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString *ID = @"annotation";
// MKAnnotationView 默认没有界面 可以显示图片
// MKPinAnnotationView有界面 默认不能显示图片
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ID];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ID];
//设置大头针颜色
annotationView.pinTintColor = [UIColor redColor];
//设置为动画掉落的效果
// annotationView.animatesDrop = YES;
//显示详情
annotationView.canShowCallout = YES;
}
return annotationView;
}
@end
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