ios: addAnnotations 到 mapView 不工作

标签 ios mkmapview

您好,我有一个带有注释对象的 NSMutableArray,下面的代码不会添加注释:

在 .h 中我有

     @property (retain, nonatomic) MarketsDataController *marketList;

在 .m 中我有(添加注释不起作用。 map 上没有显示任何内容)

    _marketList = [_marketService.marketsDataController retain];
    NSLog(@"%@!!!", [_marketList objectInListAtIndex:0].title);
    [mapView addAnnotation:[_marketList objectInListAtIndex:0]];
    [mapView addAnnotation:[_marketList objectInListAtIndex:1]];
    [mapView addAnnotation:[_marketList objectInListAtIndex:2]];

MarketsListDataController 看起来像这样:

    #import "MarketsDataController.h"

    //The following interface is used for private methods
    @interface MarketsDataController ()
    - (void)initializeMarketsList;
    @end

    @implementation MarketsDataController

    //Set initial values for instance variables
    - (id)init {
        NSLog(@"init MarketsDataController");
        if (self = [super init]) {
            [self initializeMarketsList];
            return self;
        }
        return nil;
    }

    - (void)initializeMarketsList{
        NSMutableArray *marketsList = [[NSMutableArray alloc] init]; //Initialize the product list
        _marketsList = marketsList;                      //Set the markets list to the markets list
    }

    //Return the number of products
    - (NSUInteger)countOfList {
        return [_marketsList count];
    }

    //Return a product within the list
    - (MapAnnotation *)objectInListAtIndex:(NSUInteger)theIndex {
        return [_marketsList objectAtIndex:theIndex];
    }

    - (void)addAnnotationToList:(MapAnnotation *)mapAnnotation{
        NSLog(@"Adding market");
        [_marketsList addObject:mapAnnotation];
    }

    - (void)dealloc {
        NSLog(@"DEALLOC MarketsDataController");
        [_marketsList release];
        [super dealloc];

    }

    @end

MapAnnotation .m 看起来像:

#import "MapAnnotation.h"

@implementation MapAnnotation

@synthesize coordinate, title, subtitle;

- (id)init{
    CLLocationCoordinate2D location;
    location.latitude = 0;
    location.longitude = 0;
    return [self initWithCoordinate:coordinate title:nil subtitle:nil];
}

- (id)initWithCoordinate:(CLLocationCoordinate2D) c title:(NSString *)t subtitle:(NSString *)st{
    self = [super init];
    coordinate = c;
    title = [t retain];
    subtitle = [st retain];
    return self;
}

- (void) dealloc{
    [title release];
    [subtitle release];
    [super dealloc];
}

@end

我创建它们并将它们添加到另一个类中,例如:

if (![latitude isEqual:[NSNull null]] && ![longitude isEqual:[NSNull null]]) {
                     NSLog(@"%d", i);
                    NSLog(@"%@", title);
                    CLLocationCoordinate2D coordinate;
                    coordinate.longitude = [latitude doubleValue];
                    coordinate.longitude = [longitude doubleValue];
                    [self buildMarketsList:coordinate title:title subtitle:@""]; //build the browse list product

                }

方法如下:

- (void)buildMarketsList:(CLLocationCoordinate2D)c title:(NSString *)t subtitle:(NSString *)st{
    MapAnnotation *mapAnnotation = [[MapAnnotation alloc]initWithCoordinate:c title:t subtitle:st];
    [_marketsDataController addAnnotationToList:mapAnnotation];
    [mapAnnotation release];
}   

如何添加一个实现 的注释对象数组?我没有收到任何错误,也不会显示任何注释。

最佳答案

发现问题:

改变:

                coordinate.longitude = [latitude doubleValue];
                coordinate.longitude = [longitude doubleValue];

收件人:

                coordinate.latitude = [latitude doubleValue];
                coordinate.longitude = [longitude doubleValue];

关于ios: addAnnotations 到 mapView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117281/

相关文章:

iOS 构建匹配配置文件错误 - phonegap

ios - 从 KML 文件添加注释到 MKMapView

ios - 更改 MKMapView 用户位置注释

ios - 我可以在 Phonegap Build 中为 iOS 定义自定义 URL 方案吗?

iphone - 如何在 iOS 较高的设备上使用较低的 SDK 调试 iOS 应用程序构建

iphone - 如何检测 GPS 坐标是否落在 MKMapView 上的某个区域?

cocoa-touch - 根据指南针旋转 MapView

ios - iOS6 上 MapKit 的性能问题

ios - OTA是否可以安装使用免费Apple Dev帐户签名的iOS应用

javascript - Cordova/Phonegap 在主 Cordova webview 中加载外部站点