【问题标题】:iOS, how to display route between two points using Google Places Api?iOS,如何使用 Google Places Api 显示两点之间的路线?
【发布时间】:2014-02-06 16:51:38
【问题描述】:
我一直在寻找如何在 iOS 中使用 Google Places API 在两点之间绘制路线,但我没有找到有趣的东西。您可以在两点之间绘制路线的唯一方法是调用 Web 服务并将 JSON 解析到您的应用程序中,以在两点之间路由路线。
Here 是一个参考。
问题:
是否有任何示例代码可以帮助我了解如何在两点、起点(基于用户当前位置)和目的地之间绘制路线。
【问题讨论】:
标签:
ios
google-maps
google-maps-sdk-ios
map-directions
【解决方案2】:
可以获取thisgoogle开发者的教程供参考。您可以查看this youtube 教程以获得指导。
希望这会有所帮助。干杯:)
【解决方案3】:
- (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;
}