【问题标题】:to show route from current location to moving car destination显示从当前位置到移动汽车目的地的路线
【发布时间】:2013-10-08 07:27:50
【问题描述】:

我尝试使用 Google 地图显示从当前位置到目的地的路线,但我想显示从移动对象到我当前位置的路线?

【问题讨论】:

    标签: iphone objective-c google-maps gps


    【解决方案1】:

    我希望你能从下面的 URL 中找到一种方法来实现你的功能

    http://code4app.net/category/mapview

    【讨论】:

      【解决方案2】:

      使用 nvpolyline 之类的东西

      • (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

        if ([annotation isKindOfClass:[NVPolylineAnnotation class]]) {

        return [[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation mapView:map] autorelease];
        

        }

        返回零; }

      • (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {

        // 修复某些标记位于折线后面 if ([Appdelegate.CrashUserArray 计数] > 0) {

        for (int i = 0; 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] > 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]; 如果([currSysVer 比较:reqSysVer 选项:NSNumericSearch] != NSOrderedAscending){ [自我更新PolylineAnnotationView]; } }

      • (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; region.span = 跨度; region.center = oldlocation;

        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 longitude:-73.74106999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44665999999999 longitude:-73.7409] autorelease], [[[CLLocation alloc] initWithLatitude:45.44665999999999 longitude:-73.7409] autorelease], [[[CLLocation alloc] initWithLatitude:45.44676 longitude:-73.74073] autorelease], [[[CLLocation alloc] initWithLatitude:45.44707999999999 经度:-73.73990000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44748 longitude:-73.73856000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44748 longitude:-73.73856000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44834 longitude:-73.73581] autorelease], [[[CLLocation alloc] initWithLatitude:45.44857999999999 longitude:-73.73475999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44863000000001 经度:-73.73417000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44863000000001 longitude:-73.73300999999999] autorelease], [[[CLLocation alloc] initWithLatitude:45.44795 longitude:-73.7008] autorelease], [[[CLLocation alloc] initWithLatitude:45.44784 longitude:-73.69398] autorelease], [[[CLLocation alloc] initWithLatitude:45.44775 longitude:-73.69092000000001] autorelease], [[[CLLocation alloc] initWithLatitude:45.44743999999999 longitude:-73.68584] autorelease], [[[CLLocation alloc] initWithLatitude:45.44728 longitude:-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");
        

        } }

      通过这种方法可以在地图上绘制路径

      【讨论】:

        猜你喜欢
        • 2011-11-15
        • 2017-10-21
        • 2015-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多