【发布时间】:2010-09-29 12:21:59
【问题描述】:
我正在尝试制作一张地图,在那里我可以看到我当前的位置,并查看街道的名称。
到目前为止,我可以在我的地图上放置一个图钉,但由于某种原因,我没有得到标注。 我在 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 自定义为这样。 但是我仍然无法从我的别针中获得标注,并且别针仍然是红色的。 但它应该是紫色的,什么都没有
【问题讨论】:
-
如果你的地图是从笔尖加载的,你记得把它连接起来吗?你记得设置委托吗?
-
我的代表已“连接”到我的搜索栏和 searchdisplaycontroller,它现在正在工作:P 谢谢我仍然需要弄清楚为什么我没有得到标注
-
您可以发布您的
CustomPlacemark课程吗?我看不出这不起作用的任何原因...... -
我已经找到了我没有将代理设置为我的地图视图的答案
标签: objective-c