2011-08-15 49 views

回答

1

由于显示当前位置作为注解的,我做了以下内容:

// Set up the annotation 
LocationAnnotation *annotation = [[LocationAnnotation alloc] initWithLatitude:[numberFormatter numberFromString:[[location valueForKey:@"latitude"] description]] andLongitude:[numberFormatter numberFromString:[[location valueForKey:@"longitude"] description]] andTitle:[location valueForKey:@"name"] andSubtitle:[location valueForKey:@"notes"]]; 
[numberFormatter release]; 

[self.mapView addAnnotation:annotation]; 

诠释头类看起来是这样的:

@interface LocationAnnotation : NSObject <MKAnnotation> { 

UIImage *image; 
NSNumber *latitude; 
NSNumber *longitude; 
NSString *locationTitle; 
NSString *locationSubtitle; 
} 

@property (nonatomic, retain) UIImage *image; 
@property (nonatomic, retain) NSNumber *latitude; 
@property (nonatomic, retain) NSNumber *longitude; 

@property(nonatomic,retain) NSString *locationTitle; 
@property(nonatomic,retain) NSString *locationSubtitle; 

-(id)initWithLatitude:(NSNumber *)aLatitude andLongitude:(NSNumber *)aLongitude andTitle:(NSString *)aLocationTitle andSubtitle:(NSString *)aLocationSubtitle; 

@end 

addAnnotation方法和MKAnnotation协议是你”重新寻找来实现这一点。

如果你想显示自定义位置,你会不会来围绕创建自己的MKAnnotation这里提到:

loading custom image on mkmaps

+0

我知道这一点,但那不是我想要的。我想添加我自己的注释。 – deathman91

+0

如何获取用户当前的纬度和经度viewDidAppear? – deathman91

+0

您可以通过CLLocationManager的'coordinate'属性获取当前坐标 - 请参阅:http://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html# // apple_ref/DOC/UID/TP40007126 –

1

确保您设置MKMapViewYESshowsUserLocation财产。

此属性只有使显示用户位置。