您好我正在使用自定义注释来替换蓝色 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:从 viewDidLoad 调用上一个 stackoverflow 问题并开始更新位置
我遇到的问题是注释没有显示我是否需要四处移动才能启动并更新我的位置,或者我可以在加载时设置它的状态,即显示注释,然后让它将注释更新到我的位置?如果我给出它显示的注释硬编码坐标值,但我不希望我想要它基于我的位置?
- (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];