как поставить булавки в виде карты? - PullRequest
4 голосов
/ 27 ноября 2009

Я новый пользователь в приложении для iPhone. Я хотел показать булавки в моем MKMapView . Как мне это сделать?

Дайте мне несколько ценных предложений.

Ответы [ 3 ]

4 голосов
/ 27 ноября 2009

Вам необходимо создать делегата, который реализует протокол MKAnnotation :

@interface AnnotationDelegate : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id) initWithCoordinate:(CLLocationCoordinate2D)coord;

@end

@implementation AnnotationDelegate

@synthesize coordinate;

- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
    coordinate.latitude = coord.latitude;
    coordinate.longitude = coord.longitude;
    return self;
}

@end

Для каждой из точек вашей карты вам необходимо создать один из ваших AnnotionDelegate объектов (передавая координаты точки) и добавить его в MKMapView :

AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] initWithCoordinate:coordinate] autorelease];
[self._mapView addAnnotation:annotationDelegate];
1 голос
/ 06 сентября 2011
NSString * urlString = nil;
        urlString = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",12.58, 77.35, [NSString stringWithFormat:@"%@,%@,%@",[detailInfoDict valueForKey:@"address"],[detailInfoDict valueForKey:@"city"],[detailInfoDict valueForKey:@"state"]]];
        urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]]
0 голосов
/ 08 ноября 2010
if([points retainCount] > 0)
  {
    [points release];
    points = nil;
  }


  if([annotationAry retainCount] > 0)
  {
    [annotationAry release];
    annotationAry = nil;
  }
  points = [[NSMutableArray alloc]init];
  annotationAry = [[NSMutableArray alloc]init]; 
  for(int i=0;i<[longitudeary count];i++)
  { 
    CLLocation* currentLocation1 = [[CLLocation alloc] initWithLatitude:[[latitudeary objectAtIndex:i]doubleValue] longitude:[[longitudeary objectAtIndex:i]doubleValue]];

    [points addObject:currentLocation1];
  }


  for(int i=0;i<[points count];i++)
  {
    // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP
    CSMapAnnotation* annotation = nil;

    // create the start annotation and add it to the array
      annotation = [[[CSMapAnnotation alloc] initWithCoordinate:[[points objectAtIndex:i] coordinate] 
                          annotationType:CSMapAnnotationTypeImage 
                              title:@"123456..."
                               shID:[shIDary objectAtIndex:i] 
                              catID:[catIDary objectAtIndex:i]
                             ciggUse:[ciggaretteUSEary objectAtIndex:i]
                             wifiUse:[wifiUSEary objectAtIndex:i]
                            controller:self]autorelease];


    [annotationAry addObject:annotation];
  }

  [mapViewmy addAnnotations:[NSArray arrayWithArray:annotationAry]];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...