2

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

我已经想出如何在这篇文章之后显示两点之间的路线。我正在按照这些指示构建多个点的列表。

据我了解,打开 maps.google.com(在 iOS 中)将打开地图应用程序(如果地图不可用,则打开 Safari)。

结果是地图应用程序仍然只显示起点和终点之间的路线。添加mrad参数的点不显示。

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

4

3 回答 3

3

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

但我会停止试图在那里看起来很聪明。您正在查看错误的 SO 问题和答案。您正在寻找的是一个两步过程:

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

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

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

我建议你看看它。

于 2012-05-18T08:37:00.777 回答
2

刚刚使用 Google maps api V3 编写了一个小示例以在 iOS 6+ 上显示方向 https://github.com/manishnath/iOSPlotRoutesOnMap

于 2013-10-07T05:43:26.310 回答
0

这是通过多个位置获取连接路线的简单代码。 要获得完整的项目,请继续 - 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];

}
于 2017-08-24T05:22:11.673 回答