在iOS中多点绘制路线

我正尝试在提供的地图应用程序中显示具有多个点的路线。

我已经想出了如何显示本文后两点之间的路线。 我正在按照这些方向build立多个点的列表。

据我所知,打开maps.google.com(在iOS)将打开地图应用程序(或Safari,如果地图不可用)。

结果是地图应用程序仍然只显示开始和目的地之间的路线。 没有显示用mrad参数添加的点。

是否可以在iOS中显示具有多个目的地的路线(无需构build我自己的映射系统)?

对于你的问题,答案是肯定的。

但是我会停止尝试在那里看起来聪明。 你看错了这个问题和答案。 你要找的是两个步骤:

  • 使用GMaps Directions API获取航点等列表
  • 用这些点画一条线。

幸运的是,显然有一个Github项目可以满足你的需求。 我没有使用它,所以我不知道它的质量,但肯定比我在这里解释如何做到这一点。

https://github.com/kishikawakatsumi/MapKit-Route-Directions

我build议你看看。

刚刚写了一个小样本,使用谷歌地图API V3显示方向在iOS 6 + https://github.com/manishnath/iOSPlotRoutesOnMap

这里是通过多个位置获取连接路线的简单和简单的代码。 获得完整的项目只是去 – 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]; }