本文介绍了如何在Mkmapview中基于路线绘制折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我需要在MKapview
中显示Polyline
.我已经做到了,但是我需要根据路线显示Polyline
.如果正在使用位置更新,我将得到下图所示的图像,那么它很好,我尝试存储经度和纬度,然后下次我必须显示以前的Polyline
时,我没有得到,请帮助我
Hi all I need to display Polyline
in MKapview
. I have done that but I need to show Polyline
based on route. I'm getting like below image if am using location did update then it comes good i am try to store latitude and longitude then next time i have to displayed previous Polyline
in that time i am not getting, please help me
推荐答案
- (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]);
}];
}];
}
}];
}
这篇关于如何在Mkmapview中基于路线绘制折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!