【发布时间】:2013-04-17 22:35:00
【问题描述】:
您好,我正在使用自定义注释来替换蓝色 GPS 位置点。我已经在 viewForAnnotation 中将它添加到地图中。 OurLocAnnotation 类符合 MKAnnotation 委托。
//Custom location view
if([annotation isKindOfClass:[OurLocAnnotation class]]) {
static NSString *identifier = @"currentLocation";
SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.recycleMap dequeueReusableAnnotationViewWithIdentifier:identifier];
if(pulsingView == nil) {
pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pulsingView.annotationColor = [UIColor colorWithRed:0.678431 green:0 blue:0 alpha:1];
pulsingView.canShowCallout = YES;
}
return pulsingView;
}
根据此链接将显示用户位置设置为 NO:Previous stackoverflow question 并从 viewDidLoad 调用开始更新位置
我遇到的问题是注释没有显示我是否需要四处移动它才能启动并更新我的位置,或者我可以在加载时设置它的状态,即显示注释,然后让它更新注释到我的位置?如果我给出注释硬编码的坐标值,它显示但我不希望我想要它基于我的位置?
- (void) locationManager:(CLLocationManager*) manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
{
if (ourLocAnn == nil)
{
self.ourLocAnn = [[OurLocAnnotation alloc] init];
ourLocAnn.title = @"I am here";
ourLocAnn.coordinate = newLocation.coordinate;
[recycleMap addAnnotation:ourLocAnn];
}
else
{
ourLocAnn.coordinate = newLocation.coordinate;
}
更新:我很愚蠢,我可以通过向位置经理询问我的位置来显示我的位置,如下所示。我只希望在我搬家时我的位置会更新....
ourLocAnn = [[OurLocAnnotation alloc]init];
ourLocAnn.coordinate = clController.locMgr.location.coordinate;
[recycleMap addAnnotation:ourLocAnn];
【问题讨论】:
-
发布的代码看起来不错,将其设置为 newLocation.coordinate 应该可以工作。您应该能够在模拟器中使用 Debug\Location\FreewayDrive 对其进行测试。 NSLog 你在 didUpdateToLocation 中得到的坐标。
-
@AnnaKarenina 非常感谢您花时间看起来很亲切。我将尝试模拟器方法或四处走走,看看她是否使用我的自定义用户位置注释更新正常。
-
@AnnaKarenina 我可以确认这一切正常,感谢您提供了使其正常工作的线索....
标签: ios mkmapview mkannotation mkannotationview mkpinannotationview