【问题标题】:Draw a route on GMSMapView (Google Maps iOS SDK)在 GMSMapView (Google Maps iOS SDK) 上绘制路线
【发布时间】:2016-03-08 08:34:03
【问题描述】:

我想在我的mapView (GMSMapView) 上画一条从 A 点到 B 点的路线。

我试过这样做:

GMSMutablePath *path=[GMSMutablePath path];
    [path addCoordinate:self.locationManager.location.coordinate];
    [path addCoordinate:marker.position];

    GMSPolyline *rectangle=[GMSPolyline polylineWithPath:path];
    rectangle.strokeWidth=2.f;
    rectangle.map=self.mapView;

但它只是画了一条连接点 A 和点 B 的线,而不是路线本身(通过街道、道路等的方向......)。

我想在地图上画出步行从 A 点到 B 点的最佳方式。

我该怎么做?

谢谢!

【问题讨论】:

标签: ios objective-c iphone cocoa-touch google-maps-sdk-ios


【解决方案1】:

使用谷歌地图方向 API。使用 NSURLConnection 或任何其他 3rd 方库(如 AFNetworking 等)将起始起点和目标位置点发送给它。获取 XML 或 JSON 中的响应并解析它。

【讨论】:

    【解决方案2】:

    { dispatch_async(dispatch_get_main_queue(), ^{

            PlayBackObject *displayobj=[[PlayBackObject alloc]init];
    
            displayobj=[playBackMutArray objectAtIndex:0];
    
            double distanceLatitude = [displayobj.latitudeStr doubleValue];
            double distanceLongtitude =[displayobj.longitudeStr doubleValue];
    
            CLLocationDegrees lat = distanceLatitude;
            CLLocationDegrees lon =distanceLongtitude;
    
            GMSCameraPosition* camera = [GMSCameraPosition
                                         cameraWithLatitude:lat
                                         longitude:lon
                                         zoom: 9];
    
    
            GMSMapView *ListAlertMultimap;
    
    
    
                ListAlertMultimap =[GMSMapView mapWithFrame: CGRectMake(0, 0, 414,736) camera: camera];
                [GmapPlayView addSubview:ListAlertMultimap];
    
    
    
              path = [GMSMutablePath path];
    
            for (int i = 0; i < [playBackMutArray count]-1; i++)
    
            {
    
                double lat = [[[playBackMutArray objectAtIndex:i]valueForKey:@"latitudeStr" ] doubleValue];
                double lng = [[[playBackMutArray objectAtIndex:i]valueForKey:@"longitudeStr" ] doubleValue];
    
                marker = [[GMSMarker alloc] init];
    
                marker.position = CLLocationCoordinate2DMake(lat,lng);
    
                marker.appearAnimation = kGMSMarkerAnimationPop;
                NSString *title=[[playBackMutArray objectAtIndex:i]valueForKey:@"trackeridStr"];
                NSString *speed=[[playBackMutArray objectAtIndex:i]valueForKey:@"speedStr"];
                NSString *direction=[[playBackMutArray objectAtIndex:i]valueForKey:@"directionStr"];
    
                marker.title=[NSString stringWithFormat:@"Tracker ID : %@",title];
                marker.snippet=[NSString stringWithFormat:@"Speed : %@km/hr Direction : %@",speed,direction];
    
     //         marker.icon = [UIImage imageNamed:@"marker_start"];
    
                [ListAlertMultimap setMinZoom:2 maxZoom:25];
                marker.map = ListAlertMultimap;
    
                [path addLatitude:lat longitude:lng];
            }
               NSLog(@"Direction path");
               polyline = [GMSPolyline polylineWithPath:path];
               polyline.strokeColor = [UIColor blueColor];
               polyline.strokeWidth = 5.f;
               polyline.map=ListAlertMultimap;
    
        });
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多