我一直在关注本教程,它帮助我在 map 上的 2 个点击位置之间绘制路线方向(折线)。但是,我不需要点击位置,因为当我想向用户显示路线时,我已经有了起点和目的地的纬度和经度。
我可以使用已有的经纬度数组创建 GMSPath 吗?
如果是这样,如何..?
- (void)addDirections:(NSDictionary *)json {
NSDictionary *routes = [json objectForKey:@"routes"][0];
NSDictionary *route = [routes objectForKey:@"overview_polyline"];
NSString *overview_route = [route objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.map = self.mainGoogleMap;}
最佳答案
是的,您可以通过以下方法来完成。
First you need to create NSMutablePath global object.
Then you have to add latitude and longitude in that path like below and then assign that path to polyline object and your polyline is drawn
在 View 中DidLoad
pathDynamic = [[GMSMutablePath alloc] init];
当您想在可变路径中添加位置时 CLLocation *loc = [[CLLocation alloc] initWithLatitude:[[dictData valueForKey:@"fl_route_latitude"] doubleValue] longitude:[[dictData valueForKey:@"fl_route_longitude"] doubleValue]];
[pathDynamic addCoordinate:loc.coordinate];//Add your location in mutable path
GMSPolyline *polyline = [GMSPolyline polylineWithPath:pathDynamic];
// Add the polyline to the map.
polyline.strokeColor = AppOrangeColor;
polyline.strokeWidth = 3.0f;
polyline.map = [self getMapView];
关于objective-c - 我可以使用我已有的纬度和经度而不是 pathFromEncodedPath 创建 GMSPath 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32178370/