我想製作一張地圖,在那裏我可以看到我目前的位置,看看這條街叫什麼名字。ViewForAnnotation不被稱爲
到目前爲止,我可以在我的地圖上放一個圖釘,但由於某種原因,我沒有收到標註。 和我已經在我的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是這樣。 但我仍然無法從我的引腳獲得標註,並且引腳保持紅色。 但它應該是什麼都沒有的紫色
如果你的地圖是從一個筆尖加載的,你記得把它連接起來嗎?你記得設置代表嗎? – 2010-09-29 12:32:25
我的委託人「連線」到我的搜索欄和searchdisplaycontroller它現在正在工作:P感謝我仍然需要弄清楚爲什麼我沒有得到標註 – Nico 2010-09-29 12:36:40
你可以發佈你的'CustomPlacemark'類嗎?我看不出任何理由爲什麼這不起作用... – 2010-10-01 12:29:51