objective-c - 我可以使用我已有的纬度和经度而不是 pathFromEncodedPath 创建 GMSPath 吗?

标签 objective-c google-maps gmsmapview

我一直在关注本教程,它帮助我在 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/

相关文章:

objective-c - 从我的iOS 5应用打开Twitter应用

objective-c - 将 NSNumbers 的 NSArray 转换为 NSStrings 数组的更好方法

java - Android 版 Google map 的生产 API key

iOS Google Maps API - 从另一个 View Controller 发送 GMSMapview

objective-c - 模态视图 Controller 中的 UIWebView

objective-c - 如何在NSOutlineView中制作连续的Cell?

javascript - 在圆形雷达数学方法中表示点

javascript - 谷歌地方 api 获取详细信息未返回每个地方

ios - 如何显示多条路线 IOS Mapview

ios - GMSSyncTileLayer 类 --- 如何传递我的 mapView? ..x 和 y 到底是什么?