2016-04-20 17 views
1

オフラインマップボックスに注釈/マーカーのリストを表示しようとしています。 私は、この例で与えられたソースコードを私のニーズに合わせようとしています。 mbtilesソースがあるので、mapViewにロードします。それから私は座標のリストを含むデータを持っています。自分のデータに与えられた座標に基づいてマーカーを表示したい。 しかし残念ながら私はなぜマーカーが地図に見られないのか理解できません。 ここまで私がこれまで行ってきたコードです。オフラインマップの注釈リストをマップボックスに表示

#import "ViewController.h" 
#import "AppDelegate.h" 
#import "Data.h" 
#import "Mapbox.h" 


@interface ViewController() 
@end 



@implementation ViewController 

- (void)viewDidLoad { 

    [super viewDidLoad]; 


    RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:@"FieldIQ" ofType:@"mbtiles"]; 

    RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:offlineSource]; 

    mapView.zoom = 3; 

    mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 

    mapView.adjustTilesForRetinaDisplay = YES; // these tiles aren't designed specifically for retina, so make them legible 

    [self.view addSubview:mapView]; 

    self.arrayAnnotation = [[NSMutableArray alloc]init]; 
    AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; 
    for(int i=0;i<appDelegate.datas.count;i++) 
    { 
     Data *data = (Data *)[appDelegate.datas objectAtIndex:i]; 
     NSLog(@"count %d : area %@ and name %@",i, data.addressGeographicalX, data.addressGeographicalY); 

     NSString *trimlat = [data.addressGeographicalX stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
     NSString *trimlon = [data.addressGeographicalY stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
     //Convert to double 
     double latdouble = [trimlat doubleValue]; 
     double londouble = [trimlon doubleValue]; 
     //Create coordinate 
     CLLocationCoordinate2D coord = {(latdouble),(londouble)}; 
     [mapView addAnnotation:[RMAnnotation annotationWithMapView:mapView coordinate: 
           mapView.centerCoordinate andTitle:nil]]; 

    } 
    [mapView addAnnotation:[RMAnnotation annotationWithMapView:mapView coordinate: 
          mapView.centerCoordinate andTitle:nil]]; 
    mapView.clusteringEnabled = YES; 




    //mapView.clusteringEnabled = YES; 

}- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation 
{ 
    if (annotation.isUserLocationAnnotation) 
     return nil; 

    RMMapLayer *layer = nil; 

    if (annotation.isClusterAnnotation) 
    { 
     layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"circle.png"]]; 

     layer.opacity = 0.75; 

     // set the size of the circle 
     layer.bounds = CGRectMake(0, 0, 50, 50); 

     // change the size of the circle depending on the cluster's size 
     if ([annotation.clusteredAnnotations count] > 2) { 
      layer.bounds = CGRectMake(0, 0, 70, 70); 
     } else if ([annotation.clusteredAnnotations count] > 3) { 
      layer.bounds = CGRectMake(0, 0, 100, 100); 
     } else if ([annotation.clusteredAnnotations count] > 5) { 
      layer.bounds = CGRectMake(0, 0, 120, 120); 
     } 

     [(RMMarker *)layer setTextForegroundColor:[UIColor whiteColor]]; 

     [(RMMarker *)layer changeLabelUsingText:[NSString stringWithFormat:@"%lu", 
               (unsigned long)[annotation.clusteredAnnotations count]]]; 
    } 
    else 
    { 
     layer = [[RMMarker alloc] initWithMapboxMarkerImage:@"rocket" tintColor: 
       [UIColor colorWithRed:0.224 green:0.671 blue:0.780 alpha:1.000]]; 
    } 

    return layer; 
} 

@end 
+0

ログステートメントを実行してマップ上の注釈の数を数えて、それらが追加されていないことを確認できますか?つまり、アルファは0 – DogCoffee

+0

です。ちょっと待って。 –

+1

@DogCoffee:私はそれをトレースするヒントを得たというあなたの提案をありがとう.. –

答えて

0

このケースは閉じています。 申し訳ありませんが、私はAndroidの初心者です。 実際にマーカーが描画されます。しかし、マップレイヤーが自分のマーカーを表示しないように、mapView自体を委譲しませんでした。 私はヘッダーファイルにAddによってそれを解決し、次に mapView.delegate = selfを呼び出します。

+0

関連する問題