2014-06-16 72 views
2

我想使用GMSPolyline實現該類,可以繪製箭頭而不是直線,以顯示從一個Google地圖標記指向另一個的方向。目標C是否可以使用如下所示的組合來繼承兩個類? 下面是我的鍛鍊:IOS將2個GMSMarkers之間的箭頭線繪製到GoogleMap上

#import <MessageUI/MessageUI.h> 
#import <GoogleMaps/GoogleMaps.h> 
#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 

@interface ClassA : GMSPolyline { 
} 

-(void)methodA; 

@end 

@interface ClassB : UIView { 
} 

-(void)methodB; 

@end 

@interface MyPolyline : NSObject { 
    ClassA *a; 
    ClassB *b; 
} 

-(void)methodA; 
-(void)methodB; 

@end 




- (void)addMarkers 
{ 
    if([array count] > 0){ 

     [mapView_ clear]; 
     GMSMutablePath *path = [GMSMutablePath path]; 
     GMSMutablePath *currentPath = [GMSMutablePath path]; 

     for (int i = 0; i < [array count]; i++) { 

      CheckPoints *cp = [array objectAtIndex:i]; 
      CLLocationCoordinate2D position = CLLocationCoordinate2DMake(cp.getLatitude , cp.getLongitude); 
      GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
      // GMSMarker *marker = [[GMSMarker alloc] init]; 
      marker.position = position; 
      NSLog(@"%d", cp.getState); 
      NSLog(@"%f", cp.getLatitude); 
      NSLog(@"%f", cp.getLongitude); 
      NSLog(@"%@", cp.getDesp); 
      marker.title = cp.getDesp; 

      NSString *tmpLat = [[NSString alloc] initWithFormat:@"%f", position.latitude]; 
      NSString *tmpLong = [[NSString alloc] initWithFormat:@"%f", position.longitude]; 
      marker.snippet = [NSString stringWithFormat:@"%@ %@", tmpLat,tmpLong]; 
      UIColor *color; 
      GMSPolyline *polyline ; 
      if (cp.getState ==0) { 
       color = [UIColor greenColor]; 
       [path addLatitude:cp.getLatitude longitude:cp.getLongitude]; 
      } else { 
       color = [UIColor redColor]; 
      } 
      if(i > [array indexOfObject:array.lastObject] -2){ 
       [currentPath addLatitude:cp.getLatitude longitude:cp.getLongitude]; 
      } 
      polyline = [GMSPolyline polylineWithPath:path]; 
      polyline.geodesic = YES; 
      polyline.strokeWidth = 5.f; 
     // polyline.strokeColor = [UIColor redColor]; 
      GMSStrokeStyle *solidRed = [GMSStrokeStyle solidColor:[UIColor redColor]]; 
      GMSStrokeStyle *solidRGreen = [GMSStrokeStyle solidColor:[UIColor greenColor]]; 
      polyline.spans = @[[GMSStyleSpan spanWithStyle:solidRed segments:[array count]-1], 
           [GMSStyleSpan spanWithStyle:solidRGreen segments:2]]; 
      marker.icon = [GMSMarker markerImageWithColor:color]; 
      marker.map = mapView_; 
      polyline.map = mapView_; 
     } 

    } 
} 

回答

1

不知道,如果你還在尋找一個答案,但這裏有一個選擇:使用自定義箭頭圖標添加一個GMSMarker到相應的路徑終點,設置它的旋轉根據給定線段的斜率(arctan dy/dx),確保它設置爲平面而不是廣告牌(所以它隨着用戶旋轉視圖自然旋轉)。以下是屏幕截圖:

directed GMSPolyline

+0

請問您可以爲此屏幕截圖提供代碼檢查嗎? – Den