Я пытаюсь показать маршрут от текущего местоположения до пункта назначения с помощью карты Google, но я хочу показать маршрут от движущегося объекта до моего текущего местоположения?
чтобы показать маршрут от текущего местоположения до пункта назначения движущегося автомобиля
Ответы:
используйте nvpolyline что-то вроде
(MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) аннотация {
if ([аннотация isKindOfClass:[класс NVPolylineAnnotation]]) {
return [[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation mapView:map] autorelease];
}
вернуть ноль; }
(void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
// исправлено, что какой-то маркер находится за ломаной линией if ([Appdelegate.CrashUserArray count] > 0) {
for (int i = 0; i ‹ [количество Appdelegate.CrashUserArray]; i ++) {
for (int j = 0; j < [views count]; j++) { MKAnnotationView *view = [views objectAtIndex:j]; if ([view isKindOfClass:[NVPolylineAnnotationView class]]) { [[view superview] sendSubviewToBack:view]; //view.image=[UIImage imageNamed:@"close_button.png"]; NSString *reqSysVer = @"4.0"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) { [self updatePolylineAnnotationView]; } } else { if ([[Appdelegate.CrashUserArray objectAtIndex:i] count] > 0) { nextviewbtn=[[UIButton alloc]init]; nextviewbtn.frame=CGRectMake(10,10,13,22); [nextviewbtn addTarget:self action:@selector(OpenUser:) forControlEvents:UIControlEventTouchUpInside]; nextviewbtn.tag=i; [nextviewbtn setBackgroundImage:[UIImage imageNamed:@"right_arrow.png"] forState:UIControlStateNormal]; dispatch_async(dispatch_get_global_queue(0,0), ^{ NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [[[Appdelegate.CrashUserArray objectAtIndex:i]objectAtIndex:0] objectForKey:@"userphoto_47"]]]; if ( data == nil ) return; dispatch_async(dispatch_get_main_queue(), ^{ view.image = [UIImage imageWithData: data]; view.rightCalloutAccessoryView=nextviewbtn; }); [data release]; }); } } }
}
}
[mapView setShowsUserLocation: НЕТ];
}
(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { SparkFromMapViewController *spark=[[SparkFromMapViewController alloc]initWithNibName:@"SparkFromMapViewController" bundle:nil];
if ([[Appdelegate.CrashUserDetailArray objectAtIndex:0] count] > 0) { spark.userdetailarray=[[NSMutableArray alloc] init]; spark.userdetailarray=[Appdelegate.CrashUserDetailArray objectAtIndex:0];
}
[self.navigationController pushViewController: анимированная искра: НЕТ]; [выпуск искры]; }
(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)анимированный {
NSString *reqSysVer = @"4.0"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) { [self updatePolylineAnnotationView]; } }
(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
if([annotationView isKindOfClass:[класс RegionAnnotationView]]) {
RegionAnnotationView *regionView = (RegionAnnotationView *)annotationView; RegionAnnotation *regionAnnotation = (RegionAnnotation *)regionView.annotation; if (newState == MKAnnotationViewDragStateStarting) { [regionView removeRadiusOverlay]; [locationmanager stopMonitoringForRegion:regionAnnotation.region]; } if (oldState == MKAnnotationViewDragStateDragging && newState == MKAnnotationViewDragStateEnding) { [regionView updateRadiusOverlay]; NSUserDefaults *def=[NSUserDefaults standardUserDefaults]; CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:regionAnnotation.coordinate radius:1000.0 identifier:[NSString stringWithFormat:@"%f, %f", [def floatForKey:@"currentlati"],[def floatForKey:@"currentlongi"]]]; regionAnnotation.region = newRegion; // [locationmanager startMonitoringForRegion:regionAnnotation.region desiredAccuracy:kCLLocationAccuracyBest]; }
} } -(void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aUserLocation {
регион MKCoordinateRegion; диапазон MKCoordinateSpan; span.latitudeDelta = 0,005; span.longitudeDelta = 0,005;
oldlocation.latitude = aUserLocation.coordinate.latitude; oldlocation.longitude = aUserLocation.coordinate.longitude; регион.span = диапазон; регион.центр = старое местоположение;
NSArray *points = [NSArray arrayWithObjects: [[[CLLocation alloc] initWithLatitude:45.43894 longitude:-73.7396] autorelease], [[[CLLocation alloc] initWithLatitude:45.44628 longitude:-73.74119] autorelease], [[[CLLocation alloc] initWithLatitude: 45.44649 долгота: -73.74106999999999] autorelease], [[[CLLocation alloc] initWithLatitude: 45.446659999999999 долгота: -73.7409] autorelease], [[[CLLocation alloc] initWithLatitude:45.44665999999999 autorelease[itLoithLatitude] :45.44676 долгота:-73.74073] autorelease], [[[CLLocation alloc] initWithLatitude:45.447079999999999 долгота:-73.73990000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44748 longitude:-73.7385600100000],alloc[CLautorelease[CL]autorelease[CL] initWithLatitude:45. 44748 долгота: -73.73856000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44834 долгота: -73.73581] autorelease], [[[CLLocation alloc] initWithLatitude:45.44857999999999 долгота: -73.734759999999999] autorelease [itWithLatitude] : 45.44863000000001 Долгота: -73.734170000001] Авторелеаза], [[[[Cllocation alloc] initwithlatity: 45,448630000001 долготу: -73.7330099999999], Autorelease], [[Cllocation Alloc]. initWithLatitude:45.44784 долгота:-73.69398] autorelease], [[[CLLocation alloc] initWithLatitude:45.44775 долгота:-73.69092000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44743999999999 longitude:-73.68584 [autoreleaseal] loc] initWithLatitude:45.44728 долгота:-73.68165999999999] autorelease],
[[[CLLocation alloc] initWithLatitude:45.48679000000001 longitude:-73.59443] autorelease], nil]; NVPolylineAnnotation *annotation = [[[NVPolylineAnnotation alloc] initWithPoints:points mapView:map] autorelease]; [map addAnnotation:annotation]; [loc release]; [aMapView setRegion:region animated:YES]; NSLog(@"uncomment this when you want to upload record");
} }
этим методом вы можете нарисовать путь на карте
Я надеюсь, что вы сможете найти способ реализовать свою функциональность по следующему URL-адресу.
https://code4app.net/category/mapview