在mapbox中显示离线地图中的注释列表

时间:2016-04-20 09:52:32

标签: ios objective-c iphone mapbox offline

我正在尝试在离线地图框中显示注释/标记列表。 我正在尝试将示例中给出的源代码与我的需求结合起来。 所以,我有一个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

1 个答案:

答案 0 :(得分:0)

此案已结案。 抱歉,我是Android的新手。 实际上标记是绘制的。但我没有将我的mapView委托给自己,以便地图图层不会显示我的标记。 我通过添加头文件然后调用解决了它 mapView.delegate = self。