2
A
回答
2
我有有兩個對象緯度,經度字典的數組,我這樣做 -
if ([resultArray count])
{
for (int i =0; i < [resultArray count]; i++)
{
NSDictionary *dict = [resultArray objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"lat"] floatValue];
region.center.longitude = [[dict objectForKey:@"long"] floatValue];
region.span.longitudeDelta = 70.0f;
region.span.latitudeDelta = 70.0f;
MyAnnotations *ann = [[MyAnnotations alloc] init];
ann.title = @"title";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
//
// MyAnnotation.h
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyAnnotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
//
// MyAnnotation.m
//
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize coordinate,title,subtitle;
-(void)dealloc
{
[title release];
[subtitle release];
[super dealloc];
}
@end
使用該委託標註 -
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id)annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
[defaultPinID release];
return pinView;
}
相關問題
- 1. 如何自動在其中一個註釋針上顯示地圖標註?
- 2. 鈦:如何在地圖上顯示多個註釋?
- 3. 在地圖視圖中顯示多個註釋
- 4. 在地圖註釋中顯示圖像
- 5. 如何強制顯示地圖註釋?
- 6. 如何使用webservice在iOS中顯示多個貼圖註釋?
- 7. 如何向地圖添加多個針點註釋
- 8. 地圖註釋顯示所有點的所有圖像/針腳
- 9. 如何始終顯示地圖視圖註釋標註?
- 10. 如何在地圖中顯示註釋查看
- 11. 地圖拼圖中的多個註釋
- 12. 如何在地圖視圖中添加多個註釋
- 13. 我如何在地圖上顯示多個針腳?
- 14. 如何顯示從表視圖到地圖視圖的註釋?
- 15. 如何在放大時顯示地圖註釋?
- 16. 如何在地圖上顯示多個標註objective-c
- 17. 如何顯示UIPopoverView作爲地圖視圖的註釋? (iPad)
- 18. 如何在註釋視圖上顯示更多文本
- 19. 如何在Firebug中顯示HTML註釋?
- 20. 如何在mapview中顯示pin註釋?
- 21. 在地圖視圖中突出顯示註釋
- 22. 在表格視圖中顯示地圖註釋
- 23. 在MKMapView中顯示多個註釋標註
- 24. 在註釋視圖中不顯示DetailDisclosureButton
- 25. 在大綱視圖中顯示註釋
- 26. 如何在地圖視圖中僅顯示引腳(註釋)標題?
- 27. 如何在單一點顯示多個註釋詳細信息?
- 28. 如何向地圖添加多個地標和註釋
- 29. 當點擊地圖註釋時顯示另一個視圖
- 30. 在WordPress中顯示多個地圖指針
這將在這個方法呢? - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)註釋 –
2011-05-07 05:58:54
No in viewDidLoad。 – saadnib 2011-05-07 06:00:36
顯示未聲明的MyAnnotations。 – 2011-05-07 09:52:27