【问题标题】:Plotting Route with Multiple Points in iOS在 iOS 中绘制多点路线
【发布时间】:2012-05-17 16:19:00
【问题描述】:

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

我已经弄清楚如何在this post 之后显示两点之间的路线。我在these directions 之后建立一个多点列表。

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

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

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

【问题讨论】:

    标签: ios mapkit


    【解决方案1】:

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

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

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

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

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

    我建议你看看它。

    【讨论】:

    • 我很确定在 Apple 地图上使用谷歌方向 API 是违反服务条款的。 :(
    • 这是个老问题,今天在 iOS7 上你有 MKDirections。
    【解决方案2】:

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

    【讨论】:

    • 简单而完美的一个。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多