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,236 +220,228 @@ ...@@ -226,236 +220,228 @@
// [self.mapView addAnnotation:self.track]; // [self.mapView addAnnotation:self.track];
} }
- (void)setPoint:(CLLocationCoordinate2D)point target:(NSInteger)target{ - (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle {
if (target == 1) { ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject];
CLLocationCoordinate2D position = point; alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
_selfMarker.map = nil; alertView.alertTitle.text = title;
_selfMarker = [GMSMarker markerWithPosition:position]; alertView.alertSubtitle.text = subtitle;
// _selfMarker.appearAnimation = kGMSMarkerAnimationPop; [alertView.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal];
// _selfMarker.icon = [GMSMarker markerImageWithColor:[UIColor blackColor]]; [alertView.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
_selfMarker.icon = [UIImage imageNamed:@"map_track_srart_end_icon"]; alertView.backgroundColor = [UIColor colorWithHex:000000 alpha:0.5];
_selfMarker.tracksInfoWindowChanges = YES; __weak typeof(alertView) weakAlertView = alertView;
_selfMarker.title = @"Me"; [alertView addTapBlock:^(UITapGestureRecognizer *tap) {
_selfMarker.snippet = @"WTF"; [weakAlertView removeFromSuperview];
_selfMarker.infoWindowAnchor = CGPointMake(0.5, 0.25); }];
_selfMarker.map = _GGMapView; UIView *window = [UIApplication sharedApplication].keyWindow.rootViewController.view;
[window addSubview:alertView];
return alertView;
}
CLLocationDistance distance = 100; #pragma mark 查询轨迹
_selfCircle.map = nil; - (void)queryLocationList:(ZJFriendModel *)model{
_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{ NSTimeInterval startTimeInterval = [self.stratDate timeIntervalSince1970];
CLLocationCoordinate2D position = point; NSString *intervalString = [NSString stringWithFormat:@"%.0f", startTimeInterval];
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.map = _GGMapView;
}
}
-(void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position{ NSTimeInterval endTimeInterval = [self.endDate timeIntervalSince1970];
_zoom = position.zoom; NSString *endTimeString = [NSString stringWithFormat:@"%.0f", endTimeInterval];
}
//画线,使用轨迹回放 if ([ZJUserInfoManager shared].uid.length <= 0) {
- (void)drawLineWithLocationArray:(NSArray *)locationArray{ ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.GDMapView.showsUserLocation = YES;
self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
if ([ZJUserInfoManager shared].token.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.GDMapView.showsUserLocation = YES;
self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
_initialPolyline = [[GMSPolyline alloc] init]; NSString *tid = @"";
_initiallinepath = [GMSMutablePath path];
_initialPolyline.map = nil; if (model.friendUid.length <= 0) {
tid = [ZJUserInfoManager shared].uid;
} else {
tid = model.friendUid;
}
_initialPolyline.strokeColor = [UIColor blueColor]; [self.locations removeAllObjects];
_initialPolyline.strokeWidth = 2.f; __weak typeof(self) _self = self;
[[TQNetworkTools shared] getWithAction:syncLocationDataList parameters:@{ @"endTs": [endTimeString stringByAppendingString:@"000"], @"startTs": [intervalString stringByAppendingString:@"000"], @"tid": tid} success:^(id _Nonnull response) {
CLLocationCoordinate2D startCoordinate; if([[response objectForKey:@"status"] integerValue] == 200){
CLLocationCoordinate2D endCoordinate; NSArray *results = response[@"result"][@"data"];
for(int idx = 0; idx < locationArray.count; idx++) for (NSDictionary *dict in results) {
{
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 ZJLocationModel *coordinate = [[ZJLocationModel alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude); coordinate.latitude = [dict[@"lat"] doubleValue]; //[latitude doubleValue];
[_initiallinepath addCoordinate:coordinate]; coordinate.longitude = [dict[@"lon"] doubleValue]; //[longitude doubleValue];
[_self.locations addObject:coordinate];
}
if (idx == 0) { // 去除数组中model重复
startCoordinate = coordinate; for (NSInteger i = 0; i < _self.locations.count; i++) {
for (NSInteger j = i+1; j < _self.locations.count; j++) {
ZJLocationModel *tempModel = _self.locations[i];
ZJLocationModel *model = _self.locations[j];
if (tempModel.latitude == model.latitude) {
[_self.locations removeObject:model];
} }
if (idx == locationArray.count-1){
endCoordinate = coordinate;
} }
} }
_initialPolyline.path = _initiallinepath; // [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
_initialPolyline.map = _GGMapView; // return (obj1.latitude < obj2.latitude);
// }];
_startMarker.map = nil; NSLog(@"%@", self.locations);
_startMarker = [GMSMarker markerWithPosition:startCoordinate]; if (_self.locations.count <= 0) {
_startMarker.appearAnimation = kGMSMarkerAnimationPop; [_self showAlertView];
_startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"]; // [MBProgressHUD showMessage:kLocalizedString(@"track_friend_timeWithin_no_location")];
_startMarker.title = @"start"; return;
_startMarker.map = _GGMapView; }
// [_self drawLineAction];
[_self drawLineWithLocationArray:_self.locations];
}else if ([[response objectForKey:@"status"] integerValue] == 105) {
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
}
_endMarker.map = nil; } failure:^(NSError * _Nonnull error) {
_endMarker = [GMSMarker markerWithPosition:endCoordinate]; NSLog(@"失败");
_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]; #pragma mark 获取最后一次位置
_GGMapView.camera = camera; - (void)getLastLocation:(ZJFriendModel *)model{
NSLog(@"%@", [ZJUserInfoManager shared].uid);
if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.GDMapView.showsUserLocation = YES;
self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
__weak typeof(self) _self = self;
self.actionMarker.map = nil; NSString *uid = self.model.friendUid;
self.actionMarker = [GMSMarker markerWithPosition:startCoordinate]; if (uid.length <= 0) {
self.actionMarker.icon = [UIImage imageNamed:@"map_track_move_icon"]; ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.actionMarker.title = @"move"; self.GDMapView.showsUserLocation = YES;
self.actionMarker.map = self.GGMapView; self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid;
}
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
_actionlinepath = [GMSMutablePath path]; if([[response objectForKey:@"status"] integerValue] == 200){
__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)); NSString *aa = [NSString stringWithFormat:@"%@", response[@"result"][@"data"]];
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) { if (aa.length == 6) {
return;
}
CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count]; double lat = [response[@"result"][@"data"][@"lat"] doubleValue];
[self.actionlinepath addCoordinate:coordinate]; double lon = [response[@"result"][@"data"][@"lon"] doubleValue];
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
pointAnnotation.title = @"latestLocation";
[_self.GDMapView addAnnotation:pointAnnotation];
[_self.GDMapView setCenterCoordinate:pointAnnotation.coordinate animated:false];
self.actionPolyline = [GMSPolyline polylineWithPath:self.actionlinepath]; }else if ([[response objectForKey:@"status"] integerValue] == 105) {
self.actionPolyline.strokeColor = [UIColor greenColor]; [MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
self.actionPolyline.strokeWidth = 2; }
} failure:^(NSError * _Nonnull error) {
NSLog(@"失败");
}];
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:20]; #pragma mark - AMap Function 高德
- (void) drawLineAction {
[CATransaction begin]; if (self.isMyTrack) {
[CATransaction setAnimationDuration:0.15]; [MobClick event:@"mytrack_querybutton_click"];
self.actionMarker.position = coordinate;
// self.actionMarker.rotation = location.course
[self.GGMapView animateToCameraPosition:camera];
self.actionPolyline.map = self.GGMapView;
[CATransaction commit];
count++;
}else{ }else{
dispatch_source_cancel(timer); [MobClick event:@"friendtrack_querybutton_click"];
} }
});
dispatch_resume(timer);
}
//- (void) drawLineAction { [self.trackTimeView.trackButton setSelected:true];
// [self.trackTimeView.trackButton setEnabled:false];
// if (self.isMyTrack) { //移除
// [MobClick event:@"mytrack_querybutton_click"]; [self.GDMapView removeOverlay:self.commonPolyline];
// }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 { // need get user location info
ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject]; if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); // do nothing
alertView.alertTitle.text = title; } else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
alertView.alertSubtitle.text = subtitle; //定位不能用
[alertView.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal]; [AlertControllerTool alertControllerWithTitle:kLocalizedString(@"alert_location_switch") message:kLocalizedString(@"alert_location_service") cancelTitle:kLocalizedString(@"alert_cancel") cancelBlock:^{
[alertView.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal]; } confirm:kLocalizedString(@"alert_setting") confirmBlock:^(id s) {
alertView.backgroundColor = [UIColor colorWithHex:000000 alpha:0.5]; NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
__weak typeof(alertView) weakAlertView = alertView; if([[UIApplication sharedApplication] canOpenURL:url]) {
[alertView addTapBlock:^(UITapGestureRecognizer *tap) { if (@available(iOS 10.0, *)) {
[weakAlertView removeFromSuperview]; [[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];
}]; }];
UIView *window = [UIApplication sharedApplication].keyWindow.rootViewController.view;
[window addSubview:alertView];
return alertView;
}
#pragma mark - Map Delegate
[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 { - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation {
if (annotation == self.track) { if (annotation == self.track) {
...@@ -499,8 +485,7 @@ ...@@ -499,8 +485,7 @@
} }
/// 设置折线的样式 /// 设置折线的样式
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay - (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
{
if ([overlay isKindOfClass:[MAPolyline class]]) { if ([overlay isKindOfClass:[MAPolyline class]]) {
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay]; MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
...@@ -533,126 +518,139 @@ ...@@ -533,126 +518,139 @@
// return nil; // return nil;
//} //}
#pragma mark 查询轨迹 #pragma mark - GMSMap Function google
- (void)queryLocationList:(ZJFriendModel *)model{ - (void)setPoint:(CLLocationCoordinate2D)point target:(NSInteger)target{
if (target == 1) {
NSTimeInterval startTimeInterval = [self.stratDate timeIntervalSince1970]; CLLocationCoordinate2D position = point;
NSString *intervalString = [NSString stringWithFormat:@"%.0f", startTimeInterval]; _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;
NSTimeInterval endTimeInterval = [self.endDate timeIntervalSince1970]; CLLocationDistance distance = 100;
NSString *endTimeString = [NSString stringWithFormat:@"%.0f", endTimeInterval]; _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;
if ([ZJUserInfoManager shared].uid.length <= 0) { }else{
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 CLLocationCoordinate2D position = point;
// self.mapView.showsUserLocation = YES; GMSMarker *marker = [GMSMarker markerWithPosition:position];
// self.mapView.userTrackingMode = MAUserTrackingModeFollow; marker.title = @"Hello World";
return; marker.map = _GGMapView;
}
if ([ZJUserInfoManager shared].token.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
return;
} }
}
NSString *tid = @""; //画线,使用轨迹回放
- (void)drawLineWithLocationArray:(NSArray *)locationArray{
if (model.friendUid.length <= 0) { _initialPolyline = [[GMSPolyline alloc] init];
tid = [ZJUserInfoManager shared].uid; _initiallinepath = [GMSMutablePath path];
} else {
tid = model.friendUid;
}
[self.locations removeAllObjects]; _initialPolyline.map = nil;
__weak typeof(self) _self = self;
[[TQNetworkTools shared] getWithAction:syncLocationDataList parameters:@{ @"endTs": [endTimeString stringByAppendingString:@"000"], @"startTs": [intervalString stringByAppendingString:@"000"], @"tid": tid} success:^(id _Nonnull response) {
if([[response objectForKey:@"status"] integerValue] == 200){ _initialPolyline.strokeColor = [UIColor blueColor];
NSArray *results = response[@"result"][@"data"]; _initialPolyline.strokeWidth = 2.f;
for (NSDictionary *dict in results) {
ZJLocationModel *coordinate = [[ZJLocationModel alloc] init]; CLLocationCoordinate2D startCoordinate;
coordinate.latitude = [dict[@"lat"] doubleValue]; //[latitude doubleValue]; CLLocationCoordinate2D endCoordinate;
coordinate.longitude = [dict[@"lon"] doubleValue]; //[longitude doubleValue]; for(int idx = 0; idx < locationArray.count; idx++)
[_self.locations addObject:coordinate]; {
} 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;
// 去除数组中model重复 // create our coordinate and add it to the correct spot in the array
for (NSInteger i = 0; i < _self.locations.count; i++) { CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
for (NSInteger j = i+1; j < _self.locations.count; j++) { [_initiallinepath addCoordinate:coordinate];
ZJLocationModel *tempModel = _self.locations[i];
ZJLocationModel *model = _self.locations[j]; if (idx == 0) {
if (tempModel.latitude == model.latitude) { startCoordinate = coordinate;
[_self.locations removeObject:model];
} }
if (idx == locationArray.count-1){
endCoordinate = coordinate;
} }
} }
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude);
// }];
NSLog(@"%@", self.locations); _initialPolyline.path = _initiallinepath;
if (_self.locations.count <= 0) { _initialPolyline.map = _GGMapView;
[_self showAlertView];
// [MBProgressHUD showMessage:kLocalizedString(@"track_friend_timeWithin_no_location")];
return;
}
// [_self drawLineAction];
[_self drawLineWithLocationArray:_self.locations];
}else if ([[response objectForKey:@"status"] integerValue] == 105) {
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
}
} failure:^(NSError * _Nonnull error) { _startMarker.map = nil;
NSLog(@"失败"); _startMarker = [GMSMarker markerWithPosition:startCoordinate];
}]; _startMarker.appearAnimation = kGMSMarkerAnimationPop;
} _startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"];
_startMarker.title = @"start";
_startMarker.map = _GGMapView;
#pragma mark 获取最后一次位置 _endMarker.map = nil;
- (void)getLastLocation:(ZJFriendModel *)model{ _endMarker = [GMSMarker markerWithPosition:endCoordinate];
_endMarker.appearAnimation = kGMSMarkerAnimationPop;
_endMarker.icon = [UIImage imageNamed:@"map_track_end_icon"];
_endMarker.title = @"end";
_endMarker.map = _GGMapView;
NSLog(@"%@", [ZJUserInfoManager shared].uid); //定位起始结束中心点
if ([ZJUserInfoManager shared].uid.length <= 0 || ![ZJUserInfoManager shared].isMember) { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:(startCoordinate.latitude+endCoordinate.latitude)/2 longitude:(startCoordinate.longitude+endCoordinate.longitude)/2 zoom:_zoom];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 _GGMapView.camera = camera;
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
__weak typeof(self) _self = self;
NSString *uid = self.model.friendUid; // //定位路径区域
if (uid.length <= 0) { // GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:_initiallinepath];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 // GMSCameraPosition *position = [_GGMapView cameraForBounds:bounds insets:UIEdgeInsetsZero];
// self.mapView.showsUserLocation = YES; // _GGMapView.camera = position;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid;
}
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
if([[response objectForKey:@"status"] integerValue] == 200){ 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;
NSString *aa = [NSString stringWithFormat:@"%@", response[@"result"][@"data"]]; _actionlinepath = [GMSMutablePath path];
__block NSInteger count = 0;
if (aa.length == 6) { dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
return; dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 0.16 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
} dispatch_source_set_event_handler(timer, ^{
double lat = [response[@"result"][@"data"][@"lat"] doubleValue]; if (count < self.initiallinepath.count) {
double lon = [response[@"result"][@"data"][@"lon"] doubleValue];
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
pointAnnotation.title = @"latestLocation";
// [_self.mapView addAnnotation:pointAnnotation];
// [_self.mapView setCenterCoordinate:pointAnnotation.coordinate animated:false];
}else if ([[response objectForKey:@"status"] integerValue] == 105) { CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count];
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view]; [self.actionlinepath addCoordinate:coordinate];
}
} failure:^(NSError * _Nonnull error) { self.actionPolyline = [GMSPolyline polylineWithPath:self.actionlinepath];
NSLog(@"失败"); 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;
...@@ -133,8 +134,14 @@ static ZJLocationManager * manager; ...@@ -133,8 +134,14 @@ static ZJLocationManager * manager;
}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