显示自定义对象的MKA注释

问题描述 投票:2回答:4

我有一个对象列表,每个对象都有标题,名称,描述,纬度,经度和地址。是否可以将此对象显示为MKAnnotations?我已经被这个问题困扰了几个小时了。当我尝试使对象具有CLLocationCoordinate2D时,我不断收到关于不可分配的纬度或经度的错误。

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface Oficina : NSObject <MKMapViewDelegate>

@property (nonatomic, readwrite) CLLocationCoordinate2D oficinaCoordinate;
@property (nonatomic, strong) NSString *oficinaCiudad;
@property (nonatomic, strong) NSString *oficinaEstado;
@property (nonatomic, strong) NSString *oficinaTitulo;
@property (nonatomic, strong) NSString *oficinaTelefono;
@property (nonatomic, strong) NSString *oficinaLatitud;
@property (nonatomic, strong) NSString *oficinaLongitud;
@property (nonatomic, strong) NSString *oficinaID;
@property (nonatomic, strong) NSString *oficinaDireccion;
@property (nonatomic, strong) NSString *oficinaHorario;
@property (nonatomic, strong) NSString *oficinaTipoDeOficina;
@property (nonatomic, strong) NSString *oficinaServicios;
@property (nonatomic, strong) NSString *oficinaTipoDeModulo;


@end

因此,使用互联网服务后,我得到了大约70个这些对象。现在,我希望能够将它们中的每一个转化为地图注释。这是我尝试分配纬度的方法之一,但出现错误“表达式无法分配”。

currentOffice.oficinaCoordinate.latitude = [parseCharacters floatValue];

其中currentOffice是我的自定义对象的实例。

我有一个对象列表,每个对象都有标题,名称,描述,纬度,经度和地址。是否可以将此对象显示为MKAnnotations?我已经坚持了几个小时...

ios mapkit mkannotation
4个回答
2
投票

可以将标题,名称,描述,纬度,经度和地址显示为MKA注释。


1
投票

这里有一些示例代码说明了我如何解决此问题。首先加载mapView批注数组:


0
投票

获取所窃听的MKAnnotation的对象详细信息的方法是添加:


0
投票

这非常简单,只需循环您的对象数组并创建一个MKPointAnnotation坐标,并以您想要的格式显示标题和副标题。然后通过addAnnotation方法将其添加到地图中,图钉将显示在地图上。

© www.soinside.com 2019 - 2024. All rights reserved.