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

no message

parent 767b56f0
......@@ -56,11 +56,14 @@
// if ([CLLocationManager locationServicesEnabled]) {
// [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 uploadSelfLocation:location placemark:model];
// [self uploadSelfLocation:location placemark:model];
}];
}
......
......@@ -50,7 +50,11 @@
});
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);
......
......@@ -31,23 +31,25 @@
@property (strong, nonatomic) NSDate *stratDate;
@property (strong, nonatomic) NSDate *endDate;
@property (nonatomic, strong) ZJAlertView *alertView;
@property (nonatomic, assign) BOOL refershMyself;
/********************/
@property (nonatomic, strong) MAMapView * GDMapView;
///全轨迹overlay
@property (strong, nonatomic) MAPolyline *commonPolyline;
///车头方向跟随转动
@property (nonatomic, strong) MAAnimatedAnnotation *track;
@property (nonatomic, strong) NSArray *distanceArray;
@property (nonatomic, assign) double sumDistance;
@property (nonatomic, strong) ZJAlertView *alertView;
/********************/
@property (nonatomic, strong) GMSMapView * GGMapView;
@property (nonatomic, strong) GMSCircle * selfCircle;
@property (nonatomic, strong) GMSMarker * selfMarker;
@property (nonatomic, assign) float __block zoom;
@property (nonatomic, assign) BOOL refershMyself;
@property (nonatomic, strong) GMSPolyline * initialPolyline;
@property (nonatomic, strong) GMSPolyline * actionPolyline;
@property (nonatomic, strong) NSMutableArray * arrayPolylineGreen;
......@@ -95,7 +97,11 @@
[super viewDidAppear:animated];
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);
......@@ -130,15 +136,11 @@
self.alertView.alertSubtitle.text = kLocalizedString(@"track_friend_authority_alert");
}
[self.alertView.leftButton addTapBlock:^(UITapGestureRecognizer *tap) {
NSLog(@"%@", @"leftButton");
if (self.isMyTrack) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
......@@ -147,15 +149,7 @@
[[UIApplication sharedApplication] openURL:url];
}
}
// 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 {
} else {
ZJLocationVC *locationVC = [[ZJLocationVC alloc] initWithNibName:@"ZJLocationVC" bundle:nil];
locationVC.shareButtonAction = ^{
......@@ -226,236 +220,228 @@
// [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;
- (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle {
ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject];
alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
alertView.alertTitle.text = title;
alertView.alertSubtitle.text = subtitle;
[alertView.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal];
[alertView.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
alertView.backgroundColor = [UIColor colorWithHex:000000 alpha:0.5];
__weak typeof(alertView) weakAlertView = alertView;
[alertView addTapBlock:^(UITapGestureRecognizer *tap) {
[weakAlertView removeFromSuperview];
}];
UIView *window = [UIApplication sharedApplication].keyWindow.rootViewController.view;
[window addSubview:alertView];
return alertView;
}
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;
#pragma mark 查询轨迹
- (void)queryLocationList:(ZJFriendModel *)model{
}else{
CLLocationCoordinate2D position = point;
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.map = _GGMapView;
}
}
NSTimeInterval startTimeInterval = [self.stratDate timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%.0f", startTimeInterval];
-(void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position{
_zoom = position.zoom;
}
NSTimeInterval endTimeInterval = [self.endDate timeIntervalSince1970];
NSString *endTimeString = [NSString stringWithFormat:@"%.0f", endTimeInterval];
//画线,使用轨迹回放
- (void)drawLineWithLocationArray:(NSArray *)locationArray{
if ([ZJUserInfoManager shared].uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
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];
_initiallinepath = [GMSMutablePath path];
NSString *tid = @"";
_initialPolyline.map = nil;
if (model.friendUid.length <= 0) {
tid = [ZJUserInfoManager shared].uid;
} else {
tid = model.friendUid;
}
_initialPolyline.strokeColor = [UIColor blueColor];
_initialPolyline.strokeWidth = 2.f;
[self.locations removeAllObjects];
__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;
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;
if([[response objectForKey:@"status"] integerValue] == 200){
NSArray *results = response[@"result"][@"data"];
for (NSDictionary *dict in results) {
// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
[_initiallinepath addCoordinate:coordinate];
ZJLocationModel *coordinate = [[ZJLocationModel alloc] init];
coordinate.latitude = [dict[@"lat"] doubleValue]; //[latitude doubleValue];
coordinate.longitude = [dict[@"lon"] doubleValue]; //[longitude doubleValue];
[_self.locations addObject:coordinate];
}
if (idx == 0) {
startCoordinate = coordinate;
// 去除数组中model重复
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;
_initialPolyline.map = _GGMapView;
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude);
// }];
_startMarker.map = nil;
_startMarker = [GMSMarker markerWithPosition:startCoordinate];
_startMarker.appearAnimation = kGMSMarkerAnimationPop;
_startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"];
_startMarker.title = @"start";
_startMarker.map = _GGMapView;
NSLog(@"%@", self.locations);
if (_self.locations.count <= 0) {
[_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];
}
_endMarker.map = nil;
_endMarker = [GMSMarker markerWithPosition:endCoordinate];
_endMarker.appearAnimation = kGMSMarkerAnimationPop;
_endMarker.icon = [UIImage imageNamed:@"map_track_end_icon"];
_endMarker.title = @"end";
_endMarker.map = _GGMapView;
} failure:^(NSError * _Nonnull error) {
NSLog(@"失败");
}];
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:(startCoordinate.latitude+endCoordinate.latitude)/2 longitude:(startCoordinate.longitude+endCoordinate.longitude)/2 zoom:_zoom];
_GGMapView.camera = camera;
#pragma mark 获取最后一次位置
- (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;
self.actionMarker = [GMSMarker markerWithPosition:startCoordinate];
self.actionMarker.icon = [UIImage imageNamed:@"map_track_move_icon"];
self.actionMarker.title = @"move";
self.actionMarker.map = self.GGMapView;
NSString *uid = self.model.friendUid;
if (uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.GDMapView.showsUserLocation = YES;
self.GDMapView.userTrackingMode = MAUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid;
}
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
_actionlinepath = [GMSMutablePath path];
__block NSInteger count = 0;
if([[response objectForKey:@"status"] integerValue] == 200){
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, ^{
NSString *aa = [NSString stringWithFormat:@"%@", response[@"result"][@"data"]];
if (count < self.initiallinepath.count) {
if (aa.length == 6) {
return;
}
CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count];
[self.actionlinepath addCoordinate:coordinate];
double lat = [response[@"result"][@"data"][@"lat"] doubleValue];
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];
self.actionPolyline.strokeColor = [UIColor greenColor];
self.actionPolyline.strokeWidth = 2;
}else if ([[response objectForKey:@"status"] integerValue] == 105) {
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
}
} failure:^(NSError * _Nonnull error) {
NSLog(@"失败");
}];
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:20];
#pragma mark - AMap Function 高德
- (void) drawLineAction {
[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++;
if (self.isMyTrack) {
[MobClick event:@"mytrack_querybutton_click"];
}else{
dispatch_source_cancel(timer);
[MobClick event:@"friendtrack_querybutton_click"];
}
});
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];
//
//}
[self.trackTimeView.trackButton setSelected:true];
[self.trackTimeView.trackButton setEnabled:false];
//移除
[self.GDMapView removeOverlay:self.commonPolyline];
- (ZJAlertView *)getAlertView:(NSString *)title subtitle:(NSString *)subtitle leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle {
ZJAlertView* alertView = [[[NSBundle mainBundle]loadNibNamed:@"ZJAlertView" owner:self options:nil]lastObject];
alertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
alertView.alertTitle.text = title;
alertView.alertSubtitle.text = subtitle;
[alertView.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal];
[alertView.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
alertView.backgroundColor = [UIColor colorWithHex:000000 alpha:0.5];
__weak typeof(alertView) weakAlertView = alertView;
[alertView addTapBlock:^(UITapGestureRecognizer *tap) {
[weakAlertView removeFromSuperview];
// 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];
}];
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 {
if (annotation == self.track) {
......@@ -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]]) {
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
......@@ -533,126 +518,139 @@
// return nil;
//}
#pragma mark 查询轨迹
- (void)queryLocationList:(ZJFriendModel *)model{
NSTimeInterval startTimeInterval = [self.stratDate timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%.0f", startTimeInterval];
#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;
NSTimeInterval endTimeInterval = [self.endDate timeIntervalSince1970];
NSString *endTimeString = [NSString stringWithFormat:@"%.0f", endTimeInterval];
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;
if ([ZJUserInfoManager shared].uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
if ([ZJUserInfoManager shared].token.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}else{
CLLocationCoordinate2D position = point;
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.map = _GGMapView;
}
}
NSString *tid = @"";
//画线,使用轨迹回放
- (void)drawLineWithLocationArray:(NSArray *)locationArray{
if (model.friendUid.length <= 0) {
tid = [ZJUserInfoManager shared].uid;
} else {
tid = model.friendUid;
}
_initialPolyline = [[GMSPolyline alloc] init];
_initiallinepath = [GMSMutablePath path];
[self.locations removeAllObjects];
__weak typeof(self) _self = self;
[[TQNetworkTools shared] getWithAction:syncLocationDataList parameters:@{ @"endTs": [endTimeString stringByAppendingString:@"000"], @"startTs": [intervalString stringByAppendingString:@"000"], @"tid": tid} success:^(id _Nonnull response) {
_initialPolyline.map = nil;
if([[response objectForKey:@"status"] integerValue] == 200){
NSArray *results = response[@"result"][@"data"];
for (NSDictionary *dict in results) {
_initialPolyline.strokeColor = [UIColor blueColor];
_initialPolyline.strokeWidth = 2.f;
ZJLocationModel *coordinate = [[ZJLocationModel alloc] init];
coordinate.latitude = [dict[@"lat"] doubleValue]; //[latitude doubleValue];
coordinate.longitude = [dict[@"lon"] doubleValue]; //[longitude doubleValue];
[_self.locations addObject:coordinate];
}
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;
// 去除数组中model重复
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];
// 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;
}
}
// [self.locations sortUsingComparator:^NSComparisonResult(ZJLocationModel *obj1, ZJLocationModel *obj2) {
// return (obj1.latitude < obj2.latitude);
// }];
NSLog(@"%@", self.locations);
if (_self.locations.count <= 0) {
[_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];
}
_initialPolyline.path = _initiallinepath;
_initialPolyline.map = _GGMapView;
} failure:^(NSError * _Nonnull error) {
NSLog(@"失败");
}];
}
_startMarker.map = nil;
_startMarker = [GMSMarker markerWithPosition:startCoordinate];
_startMarker.appearAnimation = kGMSMarkerAnimationPop;
_startMarker.icon = [UIImage imageNamed:@"map_track_start_icon"];
_startMarker.title = @"start";
_startMarker.map = _GGMapView;
#pragma mark 获取最后一次位置
- (void)getLastLocation:(ZJFriendModel *)model{
_endMarker.map = nil;
_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) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
return;
}
__weak typeof(self) _self = self;
//定位起始结束中心点
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:(startCoordinate.latitude+endCoordinate.latitude)/2 longitude:(startCoordinate.longitude+endCoordinate.longitude)/2 zoom:_zoom];
_GGMapView.camera = camera;
NSString *uid = self.model.friendUid;
if (uid.length <= 0) {
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
// self.mapView.showsUserLocation = YES;
// self.mapView.userTrackingMode = MAUserTrackingModeFollow;
uid = [ZJUserInfoManager shared].uid;
}
[[TQNetworkTools shared] getWithAction:getLocationDataLast parameters:@{@"tid": uid} success:^(id _Nonnull response) {
// //定位路径区域
// GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:_initiallinepath];
// GMSCameraPosition *position = [_GGMapView cameraForBounds:bounds insets:UIEdgeInsetsZero];
// _GGMapView.camera = position;
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) {
return;
}
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, ^{
double lat = [response[@"result"][@"data"][@"lat"] doubleValue];
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];
if (count < self.initiallinepath.count) {
}else if ([[response objectForKey:@"status"] integerValue] == 105) {
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
}
CLLocationCoordinate2D coordinate = [self.initiallinepath coordinateAtIndex:count];
[self.actionlinepath addCoordinate:coordinate];
} failure:^(NSError * _Nonnull error) {
NSLog(@"失败");
}];
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
......@@ -11,7 +11,12 @@
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
......@@ -19,6 +24,8 @@ typedef void(^locationUpdateInfoCallBack)(ZJLocationModel *, CLLocation *);
@property (nonatomic, strong, readonly) CLLocation * currentLocation;
@property (nonatomic, assign, readonly) ZJMapType mapType;
+ (instancetype)shared;
- (void)initWithLocationUpdateInfo:(locationUpdateInfoCallBack)callBack;
......
......@@ -109,6 +109,7 @@ static ZJLocationManager * manager;
[geocoder reverseGeocodeLocation: loctaion completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (placemarks.count > 0) {
CLPlacemark *placemark = [placemarks firstObject];
//获取城市
NSString *city = placemark.locality;
......@@ -133,8 +134,14 @@ static ZJLocationManager * manager;
}else if (error == nil && [placemarks count] == 0) {
NSLog(@"No results were returned.");
if (self.callBack) {
self.callBack(nil, nil, ZJ_GMSMapType);
}
} else if (error != nil){
NSLog(@"An error occurred = %@", error);
if (self.callBack) {
self.callBack(nil, nil, ZJ_GMSMapType);
}
}
}];
......@@ -158,8 +165,12 @@ static ZJLocationManager * manager;
[self uploadSelfLocation:location placemark:model];
BOOL isChina = NO;
isChina = [placemark.ISOcountryCode isEqualToString:@"CN"];
_mapType = isChina ? ZJ_MAMapType : ZJ_GMSMapType;
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