2011-05-07 3 views

답변

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; 
} 
+0

이이 방법으로 할 것인가를? - (MKAnnotationView *) mapView : (MKMapView *) mapView viewForAnnotation : (id ) annotation –

+0

아니요, viewDidLoad에 없습니다. – saadnib

+0

은 MyAnnotations가 선언되지 않았 음을 보여줍니다 .. –

관련 문제