我尝试使用谷歌地图显示从当前位置到目的地的路线,但我想显示从移动物体到我当前位置的路线?
答案 0 :(得分:2)
我希望您可以通过以下网址找到实现功能的方法
答案 1 :(得分:0)
使用类似
的nvpolyline(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
if([注释isKindOfClass:[NVPolylineAnnotation class]]){
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 count]; 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:NO];
}
(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { SparkFromMapViewController * spark = [[SparkFromMapViewController alloc] initWithNibName:@“SparkFromMapViewController”bundle:nil];
if([[Appdelegate.CrashUserDetailArray objectAtIndex:0] count]&gt; 0) { spark.userdetailarray = [[NSMutableArray alloc] init]; spark.userdetailarray = [Appdelegate.CrashUserDetailArray objectAtIndex:0];
}
[self.navigationController pushViewController:spark animated:NO]; [火花释放]; }
(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
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 class]]){
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; span.latitudeDelta = 0.005; span.longitudeDelta = 0.005;
oldlocation.latitude = aUserLocation.coordinate.latitude; oldlocation.longitude = aUserLocation.coordinate.longitude; region.span = span; region.center = oldlocation;
NSArray * points = [NSArray arrayWithObjects: [[[CLLocation alloc] initWithLatitude:45.43894经度:-73.7396] autorelease], [[[CLLocation alloc] initWithLatitude:45.44628经度:-73.74119] autorelease], [[[CLLocation alloc] initWithLatitude:45.44649经度:-73.74106999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44665999999999经度:-73.7409] autorelease], [[[CLLocation alloc] initWithLatitude:45.44665999999999经度:-73.7409] autorelease], [[[CLLocation alloc] initWithLatitude:45.44676经度:-73.74073] autorelease], [[[CLLocation alloc] initWithLatitude:45.44707999999999经度:-73.73990000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44748经度:-73.73856000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44748经度:-73.73856000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44834经度:-73.73581] autorelease], [[[CLLocation alloc] initWithLatitude:45.44857999999999经度:-73.73475999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44863000000001经度:-73.73417000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44863000000001经度:-73.73300999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44795经度:-73.7008] autorelease], [[[CLLocation alloc] initWithLatitude:45.44784经度:-73.69398] autorelease], [[[CLLocation alloc] initWithLatitude:45.44775经度:-73.69092000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44743999999999经度:-73.68584] autorelease], [[[CLLocation alloc] 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");
} }
通过此方法,您可以在地图上绘制路径