【问题标题】:How to draw Polyline based on route in Mkmapview如何在 Mkmapview 中根据路线绘制折线
【发布时间】:2017-02-13 17:03:52
【问题描述】:

大家好,我需要在MKapview 中显示Polyline。我已经这样做了,但我需要根据路线显示Polyline。如果使用位置确实更新了,我会像下图一样,然后它会很好我尝试存储纬度和经度,然后下次我必须在那个时候显示以前的 Polyline 时我没有得到,请帮助我

【问题讨论】:

    标签: objective-c mkmapview core-location polyline


    【解决方案1】:
    - (void)drowRoautLines_FromLocation:(CLLocationCoordinate2D)FromLocation ToLocation:(CLLocationCoordinate2D)ToLocation
    {
        MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:FromLocation
                                                   addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];
        MKMapItem *srcMapItem = [[MKMapItem alloc]initWithPlacemark:source];
        [srcMapItem setName:@"Source"];
    
        MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:ToLocation
                                                        addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];
        MKMapItem *distMapItem = [[MKMapItem alloc]initWithPlacemark:destination];
        [distMapItem setName:@"Destination"];
    
        MKDirectionsRequest *request = [[MKDirectionsRequest alloc]init];
        [request setSource:srcMapItem];
        [request setDestination:distMapItem];
        [request setTransportType:MKDirectionsTransportTypeAutomobile];
    
        MKDirections *direction = [[MKDirections alloc]initWithRequest:request];
    
        [direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error)
        {
            [self ShowLoading:NO];
    
            NSLog(@"response = %@",response);
            NSLog(@"error = %@",error);
            NSArray *arrRoutes = [response routes];
            if (arrRoutes.count == 0)
            {
                //Show Error Message.
            }
            else
            {
                [arrRoutes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
                {
    
                    MKRoute *rout = obj;
                    MKPolyline *line = [rout polyline];
                    [mapView addOverlay:line];
    
                    NSLog(@"Rout Name : %@",rout.name);
                    NSLog(@"Total Distance (in Meters) :%f",rout.distance);
                    NSArray *steps = [rout steps];
                    NSLog(@"Total Steps : %lu",(unsigned long)[steps count]);
    
                    [steps enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
                    {
                        //NSLog(@"Rout Instruction : %@",[obj instructions]);
                    }];
                }];
            }
        }];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 2016-04-12
      • 2018-11-09
      • 2015-08-12
      相关资源
      最近更新 更多