我必须使用谷歌地图显示两个位置之间的路线,但我得到的只是两个位置之间的直线,我使用下面的代码
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(@(-33.860).doubleValue,@(151.208).doubleValue)];
[path addCoordinate:CLLocationCoordinate2DMake(@(-32.860).doubleValue,@(150.208).doubleValue)];
GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
rectangle.strokeWidth = 2.f;
rectangle.map = mapView_;
self.view = mapView_;
}
请告诉我如何做到这一点,我以前见过各种此类问题,但没有得到。 请帮我... 任何帮助将不胜感激...
最佳答案
这样不行。您只向 GMSMutablePath
添加了两个坐标,因此生成的 GMSPolyline
是一条直线。
如果您想获取两点之间的路线,您需要使用路线 API,例如 Google Maps Directions API使用 HTTP 请求计算位置之间的方向。
关于ios - 在 ios 中使用 googlemap 显示两个位置之间的路线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432457/