Commit 0e962746 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

no message

parent 767b56f0
...@@ -56,11 +56,14 @@ ...@@ -56,11 +56,14 @@
// if ([CLLocationManager locationServicesEnabled]) { // if ([CLLocationManager locationServicesEnabled]) {
// [self.locationManager startUpdatingLocation]; // [self.locationManager startUpdatingLocation];
// } // }
[[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location) { [[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location, ZJMapType mapType) {
if(!model){
return;
}
[self updateMySelf:model]; [self updateMySelf:model];
// [self uploadSelfLocation:location placemark:model];
// [self uploadSelfLocation:location placemark:model];
}]; }];
} }
......
...@@ -50,7 +50,11 @@ ...@@ -50,7 +50,11 @@
}); });
self.refershMyself = YES; self.refershMyself = YES;
[[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location) { [[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location, ZJMapType mapType) {
if(!model){
return;
}
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(model.latitude, model.longitude); CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(model.latitude, model.longitude);
......
...@@ -31,23 +31,25 @@ ...@@ -31,23 +31,25 @@
@property (strong, nonatomic) NSDate *stratDate; @property (strong, nonatomic) NSDate *stratDate;
@property (strong, nonatomic) NSDate *endDate; @property (strong, nonatomic) NSDate *endDate;
@property (nonatomic, strong) ZJAlertView *alertView;
@property (nonatomic, assign) BOOL refershMyself;
/********************/
@property (nonatomic, strong) MAMapView * GDMapView;
///全轨迹overlay ///全轨迹overlay
@property (strong, nonatomic) MAPolyline *commonPolyline; @property (strong, nonatomic) MAPolyline *commonPolyline;
///车头方向跟随转动 ///车头方向跟随转动
@property (nonatomic, strong) MAAnimatedAnnotation *track; @property (nonatomic, strong) MAAnimatedAnnotation *track;
@property (nonatomic, strong) NSArray *distanceArray; @property (nonatomic, strong) NSArray *distanceArray;
@property (nonatomic, assign) double sumDistance; @property (nonatomic, assign) double sumDistance;
@property (nonatomic, strong) ZJAlertView *alertView;
/********************/
@property (nonatomic, strong) GMSMapView * GGMapView; @property (nonatomic, strong) GMSMapView * GGMapView;
@property (nonatomic, strong) GMSCircle * selfCircle; @property (nonatomic, strong) GMSCircle * selfCircle;
@property (nonatomic, strong) GMSMarker * selfMarker; @property (nonatomic, strong) GMSMarker * selfMarker;
@property (nonatomic, assign) float __block zoom; @property (nonatomic, assign) float __block zoom;
@property (nonatomic, assign) BOOL refershMyself;
@property (nonatomic, strong) GMSPolyline * initialPolyline; @property (nonatomic, strong) GMSPolyline * initialPolyline;
@property (nonatomic, strong) GMSPolyline * actionPolyline; @property (nonatomic, strong) GMSPolyline * actionPolyline;
@property (nonatomic, strong) NSMutableArray * arrayPolylineGreen; @property (nonatomic, strong) NSMutableArray * arrayPolylineGreen;
...@@ -95,7 +97,11 @@ ...@@ -95,7 +97,11 @@
[super viewDidAppear:animated]; [super viewDidAppear:animated];
self.refershMyself = YES; self.refershMyself = YES;
[[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location) { [[ZJLocationManager shared] initWithLocationUpdateInfo:^(ZJLocationModel * model, CLLocation * location, ZJMapType mapType) {
if(!model){
return;
}
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(model.latitude, model.longitude); CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(model.latitude, model.longitude);
...@@ -130,15 +136,11 @@ ...@@ -130,15 +136,11 @@
self.alertView.alertSubtitle.text = kLocalizedString(@"track_friend_authority_alert"); self.alertView.alertSubtitle.text = kLocalizedString(@"track_friend_authority_alert");
} }
[self.alertView.leftButton addTapBlock:^(UITapGestureRecognizer *tap) { [self.alertView.leftButton addTapBlock:^(UITapGestureRecognizer *tap) {
NSLog(@"%@", @"leftButton"); NSLog(@"%@", @"leftButton");
if (self.isMyTrack) { if (self.isMyTrack) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) { if([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) { if (@available(iOS 10.0, *)) {
...@@ -147,15 +149,7 @@ ...@@ -147,15 +149,7 @@
[[UIApplication sharedApplication] openURL:url]; [[UIApplication sharedApplication] openURL:url];
} }
} }
} else {
// NSDictionary * dic = [ZJUserInfoManager shared].h5_url;
// BaseWebViewController * web = [[BaseWebViewController alloc] init];
// web.title = kLocalizedString(@"mine_location_setting");
// web.neverRefreshTitle = YES;
// web.url = [dic objectForKey:@"tutorial"];
// [self.navigationController pushViewController:web animated:YES];
}
else {
ZJLocationVC *locationVC = [[ZJLocationVC alloc] initWithNibName:@"ZJLocationVC" bundle:nil]; ZJLocationVC *locationVC = [[ZJLocationVC alloc] initWithNibName:@"ZJLocationVC" bundle:nil];
locationVC.shareButtonAction = ^{ locationVC.shareButtonAction = ^{
...@@ -226,217 +220,6 @@ ...@@ -226,217 +220,6 @@
// [self.mapView addAnnotation:self.track]; // [self.mapView addAnnotation:self.track];
} }
- (void)setPoint:(CLLocationCoordinate2D)point target:(NSInteger)target{
if (target == 1) {
CLLocationCoordinate2D position = point;
_selfMarker.map = nil;
_selfMarker = [GMSMarker markerWithPosition:position];
// _selfMarker.appearAnimation = kGMSMarkerAnimationPop;
// _selfMarker.icon = [GMSMarker markerImageWithColor:[UIColor blackColor]];
_selfMarker.icon = [UIImage imageNamed:@"map_track_srart_end_icon"];
_selfMarker.tracksInfoWindowChanges = YES;
_selfMarker.title = @"Me";
_selfMarker.snippet = @"WTF";
_selfMarker.infoWindowAnchor = CGPointMake(0.5, 0.25);
_selfMarker.map = _GGMapView;
CLLocationDistance distance = 100;
_selfCircle.map = nil;
_selfCircle = [GMSCircle circleWithPosition:position radius:distance];
_selfCircle.fillColor = [kColorWithRGBA(86, 142, 252, 0.15) colorWithAlphaComponent:0.5];
_selfCircle.strokeColor = [kColorWithRGBA(86, 142, 252, 0.6) colorWithAlphaComponent:0.5];
_selfCircle.strokeWidth = 1.0;
_selfCircle.map = _GGMapView;
}else{
CLLocationCoordinate2D position = point;
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.map = _GGMapView;
}
}
-(void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position{
_zoom = position.zoom;
}
//画线,使用轨迹回放
- (void)drawLineWithLocationArray:(NSArray *)locationArray{
_initialPolyline = [[GMSPolyline alloc] init];
_initiallinepath = [GMSMutablePath path];
_initialPolyline.map = nil;
_initialPolyline.strokeColor = [UIColor blueColor];
_initialPolyline.strokeWidth = 2.f;
CLLocationCoordinate2D startCoordinate;
CLLocationCoordinate2D endCoordinate;
for(int idx = 0; idx < locationArray.count; idx++)
{
ZJLocationModel * model = [locationArray objectAtIndex:idx];
CLLocation *location = [[CLLocation alloc] initWithLatitude:model.latitude longitude:model.longitude];
// CLLocation *location = [locationArray objectAtIndex:idx];
CLLocationDegrees latitude = location.coordinate.latitude;
CLLocationDegrees longitude = location.coordinate.longitude;
// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
[_initiallinepath addCoordinate:coordinate];
if (idx == 0) {
startCoordinate = coordinate;
}
if (idx == locationArray.count-1){
endCoordinate = coordinate;
}
}
_initialPolyline.path = _initiallinepath;
_initialPolyline.map = _GGMapView;
_startMarker.map = nil;
_startMarker = [GMSMarker markerWithPosition:startCoordinate];
_startMarker.appearAnimation = kGMSMarkerAnimationPop;
_startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"];
_startMarker.title = @"start";
_startMarker.map = _GGMapView;
_endMarker.map = nil;
_endMarker = [GMSMarker markerWithPosition:endCoordinate];
_endMarker.appearAnimation = kGMSMarkerAnimationPop;
_endMarker.icon = [UIImage imageNamed:@"map_track_end_icon"];
_endMarker.title = @"end";
_endMarker.map = _GGMapView;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:(startCoordinate.latitude+endCoordinate.latitude)/2 longitude:(startCoordinate.longitude+endCoordinate.longitude)/2 zoom:_zoom];
_GGMapView.camera = camera;
self.actionMarker.map = nil;
self.actionMarker = [GMSMarker markerWithPosition:startCoordinate];
self.actionMarker.icon = [UIImage imageNamed:@"map_track_move_icon"];
self.actionMarker.title = @"move";
self.actionMarker.map = self.GGMapView;
_actionlinepath = [GMSMutablePath path];
__block NSInteger count = 0;
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 0.16 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
if (count < self.initiallinepath.count) {
CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count];
[self.actionlinepath addCoordinate:coordinate];
self.actionPolyline = [GMSPolyline polylineWithPath:self.actionlinepath];
self.actionPolyline.strokeColor = [UIColor greenColor];
self.actionPolyline.strokeWidth = 2;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:20];
[CATransaction begin];
[CATransaction setAnimationDuration:0.15];
self.actionMarker.position = coordinate;
// self.actionMarker.rotation = location.course
[self.GGMapView animateToCameraPosition:camera];
self.actionPolyline.map = self.GGMapView;
[CATransaction commit];
count++;
}else{
dispatch_source_cancel(timer);
}
});
dispatch_resume(timer);
}
//- (void) drawLineAction {
//
// if (self.isMyTrack) {
// [MobClick event:@"mytrack_querybutton_click"];
// }else{
// [MobClick event:@"friendtrack_querybutton_click"];
// }
//
// [self.trackTimeView.trackButton setSelected:true];
// [self.trackTimeView.trackButton setEnabled:false];
// //移除
// [self.mapView removeOverlay:self.commonPolyline];
//
// // need get user location info
// if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
// // do nothing
// } else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
// //定位不能用
// [AlertControllerTool alertControllerWithTitle:kLocalizedString(@"alert_location_switch") message:kLocalizedString(@"alert_location_service") cancelTitle:kLocalizedString(@"alert_cancel") cancelBlock:^{
// } confirm:kLocalizedString(@"alert_setting") confirmBlock:^(id s) {
// NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
// if([[UIApplication sharedApplication] canOpenURL:url]) {
// if (@available(iOS 10.0, *)) {
// [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
// }else{
// [[UIApplication sharedApplication] openURL:url];
// }
// }
// } finishBlock:nil];
// return;
// }
// MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init];
// pointAnnotation1.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
// pointAnnotation1.title = @"start";
// [self.mapView addAnnotation:pointAnnotation1];
//
// //构造折线数据对象
// CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
//
// for (int i = 0 ; i < self.locations.count; i++) {
// commonPolylineCoords[i].latitude = self.locations[i].latitude;
// commonPolylineCoords[i].longitude = self.locations[i].longitude;
// }
//
// MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
// pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
// pointAnnotation2.title = @"end";
// [self.mapView addAnnotation:pointAnnotation2];
//
// //构造折线对象
// MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
// self.commonPolyline = commonPolyline;
//// self.commonPolyline.boundingMapRect
// //在地图上添加折线对象
// [self.mapView addOverlay: commonPolyline];
//
// int count = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
// self.mapView.centerCoordinate = commonPolylineCoords[count/2];
// double sum = 0;
// NSMutableArray *arr = [NSMutableArray arrayWithCapacity:count];
// for(int i = 0; i < count - 1; ++i) {
// CLLocation *begin = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i].latitude longitude:commonPolylineCoords[i].longitude];
// CLLocation *end = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i+1].latitude longitude:commonPolylineCoords[i+1].longitude];
// CLLocationDistance distance = [end distanceFromLocation:begin];
// [arr addObject:[NSNumber numberWithDouble:distance]];
// sum += distance;
// }
//
// self.distanceArray = arr;
// self.sumDistance = sum;
//
// double speed_car1 = self.sumDistance / 12; //80 km/h
// // int count1 = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
// [self.track setCoordinate:commonPolylineCoords[0]];
// __weak typeof(self) weakSelf = self;
// [self.track addMoveAnimationWithKeyCoordinates:commonPolylineCoords count:count withDuration:self.sumDistance / speed_car1 withName:nil completeCallback:^(BOOL isFinished) {
// [weakSelf.trackTimeView.trackButton setEnabled:true];
// [weakSelf.trackTimeView.trackButton setSelected:false];
// }];
// [self.mapView setVisibleMapRect:self.commonPolyline.boundingMapRect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true];
//
//}
- (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle { - (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle {
ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject]; ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject];
alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
...@@ -454,85 +237,6 @@ ...@@ -454,85 +237,6 @@
return alertView; return alertView;
} }
#pragma mark - Map Delegate
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation {
if (annotation == self.track) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier1";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if(!annotationView) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES;
UIImage *imge = [UIImage imageNamed:@"map_track_move_icon"];
annotationView.image = imge;
}
return annotationView;
} else if([annotation isKindOfClass:[MAPointAnnotation class]]) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES;
}
if ([annotation.title isEqualToString:@"start"]) {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")];
} else if ([annotation.title isEqualToString:@"end"]) {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
} else {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:@"userPosition"];
}
return annotationView;
}
return nil;
}
/// 设置折线的样式
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
if ([overlay isKindOfClass:[MAPolyline class]]) {
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
polylineRenderer.lineWidth = 4.f;
polylineRenderer.strokeColor = [UIColor colorWithHex:0x568EFC];
polylineRenderer.lineJoinType = kMALineJoinRound;
polylineRenderer.lineCapType = kMALineCapRound;
return polylineRenderer;
}
return nil;
}
//- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
//{
// if ([annotation isKindOfClass:[MAPointAnnotation class]])
// {
// static NSString *reuseIndetifier = @"annotationReuseIndetifier";
// MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
// if (annotationView == nil)
// {
// annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
//reuseIdentifier:reuseIndetifier];
// }
//// annotationView.image = [UIImage imageNamed:@"gpsStat2"];
// //设置中心点偏移,使得标注底部中间点成为经纬度对应点
//// annotationView.centerOffset = CGPointMake(0, -18);
// return annotationView;
// }
// return nil;
//}
#pragma mark 查询轨迹 #pragma mark 查询轨迹
- (void)queryLocationList:(ZJFriendModel *)model{ - (void)queryLocationList:(ZJFriendModel *)model{
...@@ -544,14 +248,14 @@ ...@@ -544,14 +248,14 @@
if ([ZJUserInfoManager shared].uid.length <= 0) { if ([ZJUserInfoManager shared].uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES; self.GDMapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return; return;
} }
if ([ZJUserInfoManager shared].token.length <= 0) { if ([ZJUserInfoManager shared].token.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES; self.GDMapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return; return;
} }
...@@ -587,9 +291,9 @@ ...@@ -587,9 +291,9 @@
} }
} }
} }
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) { // [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude); // return (obj1.latitude < obj2.latitude);
// }]; // }];
NSLog(@"%@", self.locations); NSLog(@"%@", self.locations);
if (_self.locations.count <= 0) { if (_self.locations.count <= 0) {
...@@ -614,8 +318,8 @@ ...@@ -614,8 +318,8 @@
NSLog(@"%@", [ZJUserInfoManager shared].uid); NSLog(@"%@", [ZJUserInfoManager shared].uid);
if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) { if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES; self.GDMapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return; return;
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
...@@ -623,8 +327,8 @@ ...@@ -623,8 +327,8 @@
NSString *uid = self.model.friendUid; NSString *uid = self.model.friendUid;
if (uid.length <= 0) { if (uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES; self.GDMapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow; self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid; uid = [ZJUserInfoManager shared].uid;
} }
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) { [[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
...@@ -642,8 +346,8 @@ ...@@ -642,8 +346,8 @@
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init]; MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon); pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
pointAnnotation.title = @"latestLocation"; pointAnnotation.title = @"latestLocation";
// [_self.mapView addAnnotation:pointAnnotation]; [_self.GDMapView addAnnotation:pointAnnotation];
// [_self.mapView setCenterCoordinate:pointAnnotation.coordinate animated:false]; [_self.GDMapView setCenterCoordinate:pointAnnotation.coordinate animated:false];
}else if ([[response objectForKey:@"status"] integerValue] == 105) { }else if ([[response objectForKey:@"status"] integerValue] == 105) {
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view]; [MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
...@@ -652,7 +356,301 @@ ...@@ -652,7 +356,301 @@
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
NSLog(@"失败"); NSLog(@"失败");
}]; }];
}
#pragma mark - AMap Function 高德
- (void) drawLineAction {
if (self.isMyTrack) {
[MobClick event:@"mytrack_querybutton_click"];
}else{
[MobClick event:@"friendtrack_querybutton_click"];
}
[self.trackTimeView.trackButton setSelected:true];
[self.trackTimeView.trackButton setEnabled:false];
//移除
[self.GDMapView removeOverlay:self.commonPolyline];
// need get user location info
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
// do nothing
} else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
//定位不能用
[AlertControllerTool alertControllerWithTitle:kLocalizedString(@"alert_location_switch") message:kLocalizedString(@"alert_location_service") cancelTitle:kLocalizedString(@"alert_cancel") cancelBlock:^{
} confirm:kLocalizedString(@"alert_setting") confirmBlock:^(id s) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:url];
}
}
} finishBlock:nil];
return;
}
MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init];
pointAnnotation1.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
pointAnnotation1.title = @"start";
[self.GDMapView addAnnotation:pointAnnotation1];
//构造折线数据对象
CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
for (int i = 0 ; i < self.locations.count; i++) {
commonPolylineCoords[i].latitude = self.locations[i].latitude;
commonPolylineCoords[i].longitude = self.locations[i].longitude;
}
MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
pointAnnotation2.title = @"end";
[self.GDMapView addAnnotation:pointAnnotation2];
//构造折线对象
MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
self.commonPolyline = commonPolyline;
// self.commonPolyline.boundingMapRect
//在地图上添加折线对象
[self.GDMapView addOverlay: commonPolyline];
int count = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
self.GDMapView.centerCoordinate = commonPolylineCoords[count/2];
double sum = 0;
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:count];
for(int i = 0; i < count - 1; ++i) {
CLLocation *begin = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i].latitude longitude:commonPolylineCoords[i].longitude];
CLLocation *end = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i+1].latitude longitude:commonPolylineCoords[i+1].longitude];
CLLocationDistance distance = [end distanceFromLocation:begin];
[arr addObject:[NSNumber numberWithDouble:distance]];
sum += distance;
}
self.distanceArray = arr;
self.sumDistance = sum;
double speed_car1 = self.sumDistance / 12; //80 km/h
// int count1 = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
[self.track setCoordinate:commonPolylineCoords[0]];
__weak typeof(self) weakSelf = self;
[self.track addMoveAnimationWithKeyCoordinates:commonPolylineCoords count:count withDuration:self.sumDistance / speed_car1 withName:nil completeCallback:^(BOOL isFinished) {
[weakSelf.trackTimeView.trackButton setEnabled:true];
[weakSelf.trackTimeView.trackButton setSelected:false];
}];
[self.GDMapView setVisibleMapRect:self.commonPolyline.boundingMapRect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true];
}
#pragma mark - AMap Delegate 高德
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation {
if (annotation == self.track) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier1";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if(!annotationView) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES;
UIImage *imge = [UIImage imageNamed:@"map_track_move_icon"];
annotationView.image = imge;
}
return annotationView;
} else if([annotation isKindOfClass:[MAPointAnnotation class]]) {
NSString *pointReuseIndetifier = @"pointReuseIndetifier3";
MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
annotationView.canShowCallout = YES;
}
if ([annotation.title isEqualToString:@"start"]) {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")];
} else if ([annotation.title isEqualToString:@"end"]) {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
} else {
annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:@"userPosition"];
}
return annotationView;
}
return nil;
}
/// 设置折线的样式
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
if ([overlay isKindOfClass:[MAPolyline class]]) {
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
polylineRenderer.lineWidth = 4.f;
polylineRenderer.strokeColor = [UIColor colorWithHex:0x568EFC];
polylineRenderer.lineJoinType = kMALineJoinRound;
polylineRenderer.lineCapType = kMALineCapRound;
return polylineRenderer;
}
return nil;
}
//- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
//{
// if ([annotation isKindOfClass:[MAPointAnnotation class]])
// {
// static NSString *reuseIndetifier = @"annotationReuseIndetifier";
// MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
// if (annotationView == nil)
// {
// annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
//reuseIdentifier:reuseIndetifier];
// }
//// annotationView.image = [UIImage imageNamed:@"gpsStat2"];
// //设置中心点偏移,使得标注底部中间点成为经纬度对应点
//// annotationView.centerOffset = CGPointMake(0, -18);
// return annotationView;
// }
// return nil;
//}
#pragma mark - GMSMap Function google
- (void)setPoint:(CLLocationCoordinate2D)point target:(NSInteger)target{
if (target == 1) {
CLLocationCoordinate2D position = point;
_selfMarker.map = nil;
_selfMarker = [GMSMarker markerWithPosition:position];
// _selfMarker.appearAnimation = kGMSMarkerAnimationPop;
// _selfMarker.icon = [GMSMarker markerImageWithColor:[UIColor blackColor]];
_selfMarker.icon = [UIImage imageNamed:@"map_track_srart_end_icon"];
_selfMarker.tracksInfoWindowChanges = YES;
_selfMarker.title = @"Me";
_selfMarker.snippet = @"WTF";
_selfMarker.infoWindowAnchor = CGPointMake(0.5, 0.25);
_selfMarker.map = _GGMapView;
CLLocationDistance distance = 100;
_selfCircle.map = nil;
_selfCircle = [GMSCircle circleWithPosition:position radius:distance];
_selfCircle.fillColor = [kColorWithRGBA(86, 142, 252, 0.15) colorWithAlphaComponent:0.5];
_selfCircle.strokeColor = [kColorWithRGBA(86, 142, 252, 0.6) colorWithAlphaComponent:0.5];
_selfCircle.strokeWidth = 1.0;
_selfCircle.map = _GGMapView;
}else{
CLLocationCoordinate2D position = point;
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.map = _GGMapView;
}
}
//画线,使用轨迹回放
- (void)drawLineWithLocationArray:(NSArray *)locationArray{
_initialPolyline = [[GMSPolyline alloc] init];
_initiallinepath = [GMSMutablePath path];
_initialPolyline.map = nil;
_initialPolyline.strokeColor = [UIColor blueColor];
_initialPolyline.strokeWidth = 2.f;
CLLocationCoordinate2D startCoordinate;
CLLocationCoordinate2D endCoordinate;
for(int idx = 0; idx < locationArray.count; idx++)
{
ZJLocationModel * model = [locationArray objectAtIndex:idx];
CLLocation *location = [[CLLocation alloc] initWithLatitude:model.latitude longitude:model.longitude];
// CLLocation *location = [locationArray objectAtIndex:idx];
CLLocationDegrees latitude = location.coordinate.latitude;
CLLocationDegrees longitude = location.coordinate.longitude;
// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
[_initiallinepath addCoordinate:coordinate];
if (idx == 0) {
startCoordinate = coordinate;
}
if (idx == locationArray.count-1){
endCoordinate = coordinate;
}
}
_initialPolyline.path = _initiallinepath;
_initialPolyline.map = _GGMapView;
_startMarker.map = nil;
_startMarker = [GMSMarker markerWithPosition:startCoordinate];
_startMarker.appearAnimation = kGMSMarkerAnimationPop;
_startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"];
_startMarker.title = @"start";
_startMarker.map = _GGMapView;
_endMarker.map = nil;
_endMarker = [GMSMarker markerWithPosition:endCoordinate];
_endMarker.appearAnimation = kGMSMarkerAnimationPop;
_endMarker.icon = [UIImage imageNamed:@"map_track_end_icon"];
_endMarker.title = @"end";
_endMarker.map = _GGMapView;
//定位起始结束中心点
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:(startCoordinate.latitude+endCoordinate.latitude)/2 longitude:(startCoordinate.longitude+endCoordinate.longitude)/2 zoom:_zoom];
_GGMapView.camera = camera;
// //定位路径区域
// GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:_initiallinepath];
// GMSCameraPosition *position = [_GGMapView cameraForBounds:bounds insets:UIEdgeInsetsZero];
// _GGMapView.camera = position;
self.actionMarker.map = nil;
self.actionMarker = [GMSMarker markerWithPosition:startCoordinate];
self.actionMarker.icon = [UIImage imageNamed:@"map_track_move_icon"];
self.actionMarker.title = @"move";
self.actionMarker.map = self.GGMapView;
_actionlinepath = [GMSMutablePath path];
__block NSInteger count = 0;
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 0.16 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
if (count < self.initiallinepath.count) {
CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count];
[self.actionlinepath addCoordinate:coordinate];
self.actionPolyline = [GMSPolyline polylineWithPath:self.actionlinepath];
self.actionPolyline.strokeColor = [UIColor greenColor];
self.actionPolyline.strokeWidth = 2;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:20];
[CATransaction begin];
[CATransaction setAnimationDuration:0.15];
self.actionMarker.position = coordinate;
// self.actionMarker.rotation = location.course
[self.GGMapView animateToCameraPosition:camera];
self.actionPolyline.map = self.GGMapView;
[CATransaction commit];
count++;
}else{
dispatch_source_cancel(timer);
}
});
dispatch_resume(timer);
}
#pragma mark - GMSMap Delegate google
-(void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position{
_zoom = position.zoom;
} }
@end @end
...@@ -11,7 +11,12 @@ ...@@ -11,7 +11,12 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void(^locationUpdateInfoCallBack)(ZJLocationModel *, CLLocation *); typedef enum : NSUInteger {
ZJ_GMSMapType,
ZJ_MAMapType
} ZJMapType;
typedef void(^locationUpdateInfoCallBack)(ZJLocationModel * _Nullable, CLLocation * _Nullable , ZJMapType);
@interface ZJLocationManager : NSObject @interface ZJLocationManager : NSObject
...@@ -19,6 +24,8 @@ typedef void(^locationUpdateInfoCallBack)(ZJLocationModel *, CLLocation *); ...@@ -19,6 +24,8 @@ typedef void(^locationUpdateInfoCallBack)(ZJLocationModel *, CLLocation *);
@property (nonatomic, strong, readonly) CLLocation * currentLocation; @property (nonatomic, strong, readonly) CLLocation * currentLocation;
@property (nonatomic, assign, readonly) ZJMapType mapType;
+ (instancetype)shared; + (instancetype)shared;
- (void)initWithLocationUpdateInfo:(locationUpdateInfoCallBack)callBack; - (void)initWithLocationUpdateInfo:(locationUpdateInfoCallBack)callBack;
......
...@@ -109,6 +109,7 @@ static ZJLocationManager * manager; ...@@ -109,6 +109,7 @@ static ZJLocationManager * manager;
[geocoder reverseGeocodeLocation: loctaion completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { [geocoder reverseGeocodeLocation: loctaion completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (placemarks.count > 0) { if (placemarks.count > 0) {
CLPlacemark *placemark = [placemarks firstObject]; CLPlacemark *placemark = [placemarks firstObject];
//获取城市 //获取城市
NSString *city = placemark.locality; NSString *city = placemark.locality;
...@@ -128,13 +129,19 @@ static ZJLocationManager * manager; ...@@ -128,13 +129,19 @@ static ZJLocationManager * manager;
//   NSLog(@"subLocality, %@",placemark.subLocality); //   NSLog(@"subLocality, %@",placemark.subLocality);
// 国家 // 国家
//    NSLog(@"country,%@",placemark.country); //    NSLog(@"country,%@",placemark.country);
[self updateLocation:loctaion placemark:placemark]; [self updateLocation:loctaion placemark:placemark];
}else if (error == nil && [placemarks count] == 0) { }else if (error == nil && [placemarks count] == 0) {
NSLog(@"No results were returned."); NSLog(@"No results were returned.");
if (self.callBack) {
self.callBack(nil, nil, ZJ_GMSMapType);
}
} else if (error != nil){ } else if (error != nil){
NSLog(@"An error occurred = %@", error); NSLog(@"An error occurred = %@", error);
if (self.callBack) {
self.callBack(nil, nil, ZJ_GMSMapType);
}
} }
}]; }];
...@@ -158,8 +165,12 @@ static ZJLocationManager * manager; ...@@ -158,8 +165,12 @@ static ZJLocationManager * manager;
[self uploadSelfLocation:location placemark:model]; [self uploadSelfLocation:location placemark:model];
BOOL isChina = NO;
isChina = [placemark.ISOcountryCode isEqualToString:@"CN"];
_mapType = isChina ? ZJ_MAMapType : ZJ_GMSMapType;
if (_callBack) { if (_callBack) {
_callBack(model, location); _callBack(model, location, _mapType);
} }
} }
......
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