- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试制作一张 map ,在那里我可以看到我当前的位置,并看到这条街叫什么。
到目前为止,我可以在我的 map 上放置图钉,但出于某种原因,我没有收到标注。并且我在我的 viewForAnnotation 方法中放置了一个 NSLog,但它没有被调用,所以我无法测试它。
谁能帮帮我?
-(void)lat:(float)lat lon:(float)lon
{
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;
NSLog(@"Latitude: %f, Longitude: %f",location.latitude, location.longitude);
//One location is obtained.. just zoom to that location
MKCoordinateRegion region;
region.center=location;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta=.005f;
span.longitudeDelta=.005f;
region.span=span;
[map setRegion:region animated:TRUE];
//MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:location];
//geocoder.delegate=self;
//[geocoder start];
if (cPlacemark != nil) {
[map removeAnnotation:cPlacemark];
}
cPlacemark=[[CustomPlacemark alloc] initWithCoordinate:location];
cPlacemark.title = mPlacemark.thoroughfare;
cPlacemark.subtitle = mPlacemark.locality;
[map addAnnotation:cPlacemark];
[cPlacemark release];
[mLocationManager stopUpdatingLocation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
if ([annotation isKindOfClass:[CustomPlacemark class]]){
MKPinAnnotationView *pinView=(MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:@"customIdentifier"];
if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView* cPinAnnoView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:@"customIdentifier"] autorelease];
cPinAnnoView.pinColor = MKPinAnnotationColorPurple;
cPinAnnoView.animatesDrop = YES;
cPinAnnoView.canShowCallout = YES;
// Add button
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[leftButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
cPinAnnoView.leftCalloutAccessoryView = leftButton;
} else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
现在我已经将我的 viewForAnnotation 定制成这样。但我仍然无法从我的图钉中得到标注,图钉仍然是红色的。但它应该是什么都没有的紫色
最佳答案
我有同样的问题,就是没有将 MapView 委托(delegate)设置为文件所有者。
关于objective-c - 未调用 ViewForAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3821515/
我正在创建自定义注释,并且正在尝试使用 dequeueReusableAnnotation。 引脚之间的区别在于用于引脚图像的 png。 我创建了 myAnnotation 类,并在创建注释时使用了此
扫描了所有类似的问题并尝试了所有可能的解决方案后,我仍然找不到适合我的情况的解决方案。我尝试在我的 MapView 上放置多个图钉,但似乎无法正常添加我的图钉。我在 viewDidLoad 方法中启动
在我的 viewForAnnotation 方法中,我在图钉右侧添加了一个详细信息披露按钮,但它会将 showsUserLocation 更改为红色图钉,并且在“当前位置”文本右侧有一个披露按钮。 如
我正在 map 上显示图钉,但无法自定义注释 View 的显示。出于某种原因,我的 viewForAnnotation 没有被调用。这是 didFinishLaunchingWithOptions 方
我已经添加UIViewController在 .h 中并已添加 -(void) viewDidLoad { self.mapView.delegate = self; } 但是 view
我已经实现了 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {方法来更改 us
我正在尝试制作自定义注释。我制作了一个自定义注释类,我在其中设计了注释 View 。我试图在我的 Viewcontroller 中调用 viewForAnnotation 中的类。当我运行该应用程序时
最近我在我的应用程序中实现了 viewForAnnotation 方法,以使用我的注释的特征(图像、颜色等)。唯一的问题是,虽然该功能在我的代码中,但定位服务的行为很奇怪。蓝色位置标记不是“脉动”并且
我的 viewForAnnotation 在 iOS8 中运行良好,但在 iOS9 中不显示自定义图钉图像。图片路径没问题。 怎么了 ?谢谢! func mapView(mapView: MKMapV
在我花了 2 天时间搜索错误后,我不得不在这里寻求帮助。我有 MapViewController 并在 map 上放置了一些图钉。我从苹果代码示例的 MapCallouts 和 WeatherMap
我添加了这个: func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
目标是根据存储在结构数组中的某些值自定义引脚颜色。 根据此处的一些帮助,我实现了以下 viewForAnnotation 委托(delegate)方法,并且根据我的结构数据数组的大小在循环中迭代调用此
我正在尝试制作一张 map ,在那里我可以看到我当前的位置,并看到这条街叫什么。 到目前为止,我可以在我的 map 上放置图钉,但出于某种原因,我没有收到标注。并且我在我的 viewForAnnota
我知道这个问题之前已经被其他人问过,并且我之前已经在这个论坛上阅读过它们,但是到目前为止我已经尝试了所有建议的方法,但没有运气,所以我决定发布这个问题。 我在下面有这段代码,用于更改 MKMapVie
我将一个完美运行的 6.1 应用程序升级到了 Xcode 5/ios 7使用 MKMapKit 在 map View 上显示一些图钉。 现在注释图钉不显示了。我确定我的 mapview 委托(dele
我想创建基本的个人资料图像注释而不是默认注释图钉,但我不知道在这种情况下如何使用 viewForAnnotation。 有没有办法创建类似 tableView 页眉页脚 View 的 xib 文件?或
当我没有在 MKMapView 上设置委托(delegate)而是添加注释时,它们的图像如下所示: 但是,如果我像这样返回一个 MKAnnotationView: func mapView(_ map
我正在尝试在 MKMapView 上显示自定义图钉。这些图钉将具有自定义图像以及将显示值的 UILabel。 我能够成功创建带有标签的自定义图钉。现在标签显示静态值。我从像解析这样的后端服务中查询数据
我有不同的类(MKAnnotation 子类)代表 map 注释。 我将它们加载到 map 上,一切正常,但是当我移动或缩放 map 图钉时,它们的图像开始丢失。 当我平移 map viewForAn
我看过其他关于此的报告,但似乎没有一个适用。我们的应用程序因频繁(但无法可靠地重现)崩溃而瘫痪,如下所示: Thread 0 name: Dispatch queue: com.apple.main
我是一名优秀的程序员,十分优秀!