iOS,如何使用Google Places Api显示两点之间的路线?

时间:2014-02-06 16:51:38

标签: ios google-maps google-maps-sdk-ios map-directions

我一直在寻找如何使用iOS中的Google Places API在两点之间绘制路线,但我没有找到有趣的东西。在两点之间绘制路径的唯一方法是调用Web服务并将JSON解析到您的应用程序中,以在两点之间路由路由。 Here是一个参考。

问题:

是否有任何示例代码可以帮助我如何在两点之间绘制路线,原点(基于用户当前位置)和目的地。

3 个答案:

答案 0 :(得分:0)

我使用了this library,功能非常强大......你可以在两点之间绘制方向以及更多

答案 1 :(得分:0)

您可以获取Google开发人员的this教程以供参考。您可以查看this youtube教程以获取指导。

希望这会有所帮助。干杯:)

答案 2 :(得分:-1)

- (void)viewDidLoad {
    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:30.692408
                                                            longitude:76.767556
                                                                 zoom:14];
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView.myLocationEnabled = YES;

    // Creates  markers in the center of the map.


    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(30.6936659,  76.77201819999999);
    marker.title = @"Chandigarh 47c";
    marker.snippet = @"Hello World";
    marker.map = mapView;

    GMSMarker *marker1 = [[GMSMarker alloc] init];
    marker1.position = CLLocationCoordinate2DMake(30.742138,  76.818756);
    marker1.title = @"Sukhna Lake";
    marker1.map = mapView;
    //creating a path

    GMSMutablePath *path = [GMSMutablePath path];
    [path addCoordinate:CLLocationCoordinate2DMake(@(30.6936659).doubleValue,@(76.77201819999999).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(30.742138).doubleValue,@(76.818756).doubleValue)];

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