2017-02-25 13 views
12

iOSの最新のGoogleマップAPIを使用してポリラインを描画しています。私はポリラインをポイントごとに構築していますが、マップからポリラインが消える(文字通りではありません)とズームインすると、レンダリングが単純に表示されるため正しくレンダリングされません。Googleは完全にレンダリングされないポリラインをマップします

Zoomed in view これは、ポリラインは

Zoomed out view ズームインときには、ズームアウトし、ここで

がポリライン

RCPolyline *polyline = [[RCPolyline alloc] init]; 
[polyline drawPolylineFromPoint:self.selectedEmployee.location toPoint:location]; 

を描画するための私の関数であるとき、私はオーバーライドを持っている表示方法で表示する方法ですinit: RCPolylineがこのようなものになるようにする

- (instancetype)init { 
self = [super init]; 
if (self) { 
    self.strokeWidth = 5.0f; 
    self.strokeColor = UIColor.redColor; 
    self.geodesic = YES; 
    self.map = [RCMapView sharedMapView]; 
} 
return self;} 

drawPolylineFromPoint:toPoint:この

- (void)drawPolylineFromPoint:(CLLocation *)pointX toPoint:(CLLocation *)pointY { 
     GMSMutablePath *path = [GMSMutablePath path]; 
     [path addCoordinate:pointX.coordinate]; 
     [path addCoordinate:pointY.coordinate]; 
     self.path = path;} 
+0

ポリラインのパスデータが多すぎると思います。 – wf9a5m75

+0

@ wf9a5m75とはどのように関連していますか? –

+0

パスの描画点はメモリを使用します。多数のポイントは、iOS向けGoogleマップSDKが大量のメモリを使用することを意味します。私はそれが理由だと思う。 ポイントを減らすために、パスをエンコードすることができます。 ここをクリックhttp://stackoverflow.com/questions/30393067/google-maps-ios-sdk-level-of-detail-polylines – wf9a5m75

答えて

4

私はRCPolylineクラスのローカルインスタンスを作っていたし、私が望んでいるからポリラインを構築するための方法呼んでいた、グリッチを発見したがRCPolylineのグローバルオブジェクトを持っていることだったん

- (instancetype)initWithMap:(GMSMapView *)mapView { 
    self = [super init]; 
    if (self) { 
     self.strokeWidth = 4.0f; 
     self.strokeColor = [UIColor redColor]; 
     self.geodesic = YES; 
     self.map = mapView; 
     self.mutablePath = [GMSMutablePath path]; 
    } 
     return self;} 
:このような RCPolylineクラスのインスタンスの GMSPath

何かをインスタンスと更新210

今、私は同じインスタンスからこのメソッドを呼び出しています。

- (void)appendPolylineWithCoordinate:(CLLocation *)location { 
    [self.mutablePath addCoordinate:location.coordinate]; 
    self.path = self.mutablePath;} 

PS:RCPolylineGMSPolyline

0

のサブクラスは、このコードを試してみてくださいです。

- (void)fetchPolylineWithOrigin:(CLLocation *)origin destination:(CLLocation *)destination { 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lat longitude:longg zoom:12]; 
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView.myLocationEnabled = YES; 
    self.view = mapView; 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.map = mapView; 
    NSString *originString = [NSString stringWithFormat:@"%f,%f", origin.coordinate.latitude, origin.coordinate.longitude]; 
    NSString *destinationString = [NSString stringWithFormat:@"%f,%f", destination.coordinate.latitude, destination.coordinate.longitude]; 
    NSString *directionsAPI = @"https://maps.googleapis.com/maps/api/directions/json?"; 
    NSString *directionsUrlString = [NSString stringWithFormat:@"%@&origin=%@&destination=%@&mode=driving&key=%@&alternatives=true", directionsAPI, originString, destinationString,@"YOUR API KEY"]; 
    NSURL *directionsUrl = [NSURL URLWithString:directionsUrlString]; 
    NSURLSessionDataTask *fetchDirectionsTask = [[NSURLSession sharedSession] dataTaskWithURL:directionsUrl completionHandler: 
               ^(NSData *data, NSURLResponse *response, NSError *error) 
               { 
                NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
                if(error) 
                { 
                 return; 
                } 
                NSArray *routesArray = [json objectForKey:@"routes"]; 
                GMSPolyline *polyline = nil; 
                int i=1; 
                for (id route in routesArray) 
                { 
                 NSDictionary *routeDict = [route valueForKey:@"overview_polyline"]; 
                 NSString *points = [routeDict objectForKey:@"points"]; 
                 GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init]; 
                 GMSPath *path = [GMSPath pathFromEncodedPath:points]; 
                 polyline = [GMSPolyline polylineWithPath:path]; 
                 polyline.strokeWidth = 3; 
                 if(i==1) 
                 { 
                  polyline.strokeColor = [UIColor greenColor]; 

                 }else if(i==2) 
                 { 
                  polyline.strokeColor = [UIColor redColor]; 
                 }else{ 
                  polyline.strokeColor = [UIColor blueColor]; 
                 } 
                 i = i+1; 

                 bounds = [bounds includingCoordinate:marker.position]; 
                 polyline.map=mapView; 
                } 
               }]; 
    [fetchDirectionsTask resume]; 
} 
+0

私は2つの座標間のルートを取得するAPIを使用していない私は、ユーザーが移動し、それをプロットとして位置データを記録しています –

関連する問題