我试图在提供的地图应用程序中显示具有多个点的路线。在iOS中绘制具有多个点的路线
我已经想出了如何在this post之后的两点之间显示路线。我正在建立一个these directions以下的多个点的列表。
据我所知,打开maps.google.com(在iOS中)将打开地图应用程序(如果地图不可用,则为Safari)。
结果是地图应用程序仍然只显示开始和目的地之间的路线。没有显示与mrad
参数相加的点数。
是否可以在iOS中显示具有多个目的地的路线(无需构建我自己的映射系统)?
我试图在提供的地图应用程序中显示具有多个点的路线。在iOS中绘制具有多个点的路线
我已经想出了如何在this post之后的两点之间显示路线。我正在建立一个these directions以下的多个点的列表。
据我所知,打开maps.google.com(在iOS中)将打开地图应用程序(如果地图不可用,则为Safari)。
结果是地图应用程序仍然只显示开始和目的地之间的路线。没有显示与mrad
参数相加的点数。
是否可以在iOS中显示具有多个目的地的路线(无需构建我自己的映射系统)?
对于你的问题,答案是肯定的。
但我会停止尝试在那里看起来聪明。你看着错误的SO问题和答案。你所寻找的是一个两个步骤:
幸运的是,显然有一个Github项目可以满足您的需求。我没有使用它,所以我不知道它的质量,但肯定比我在这里解释如何做到这一点。
https://github.com/kishikawakatsumi/MapKit-Route-Directions
我劝你看看吧。
这里是简单和容易的代码通过多个位置,可以连接路径一小部分。 获得完整的项目只是去导通https://github.com/vikaskumar113/RouteWithMultipleLocation
NSArray *dictionary = @[
@{
@"Source_lat": @"28.6287",
@"Source_lon": @"77.3208",
@"Dest_lat": @"28.628454",
@"Dest_lon": @"77.376945",
@"S_address": @"Vaishali,Delhi",
},
@{
@"Source_lat": @"28.628454",
@"Source_lon": @"77.376945",
@"Dest_lat": @"28.5529",
@"Dest_lon": @"77.3367",
@"S_address": @"Noida Sec 63",
},
@{
@"Source_lat": @"28.5529",
@"Source_lon": @"77.3367",
@"Dest_lat": @"28.6276",
@"Dest_lon": @"77.2784",
@"S_address": @"Noida Sec 44",
},
@{
@"Source_lat": @"28.6276",
@"Source_lon": @"77.2784",
@"Dest_lat": @"28.6287",
@"Dest_lon": @"77.3208",
@"S_address": @"Laxmi Nagar,Delhi",
},
];
for (int i=0; i<dictionary.count; i++) {
NSDictionary*dict=[dictionary objectAtIndex:i];
NSString*S_lat=[dict valueForKey:@"Source_lat"];
NSString*S_lon=[dict valueForKey:@"Source_lon"];
NSString*D_lat=[dict valueForKey:@"Dest_lat"];
NSString*D_lon=[dict valueForKey:@"Dest_lon"];
NSString*address=[dict valueForKey:@"S_address"];
NSString* apiUrlStr =[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@,%@&destination=%@,%@&sensor=false",S_lat,S_lon, D_lat, D_lon
];
NSData *data =[NSData dataWithContentsOfURL:[NSURL URLWithString:apiUrlStr]];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
CLLocationCoordinate2D coord;
coord.latitude=[S_lat floatValue];
coord.longitude=[ S_lon floatValue];
MKCoordinateRegion region1;
region1.center=coord;
region1.span.longitudeDelta=0.2 ;
region1.span.latitudeDelta=0.2;
[theMapView setRegion:region1 animated:YES];
MKPointAnnotation *sourceAnnotation = [[MKPointAnnotation alloc]init];
sourceAnnotation.coordinate=coord;
sourceAnnotation.title=address;
[theMapView addAnnotation:sourceAnnotation];
}
我敢肯定,这是对服务条款使用谷歌API的方向的苹果地图上。 :( – deepwinter
这是一个老问题,今天在iOS7上你有MKDirections。 –