Как я добавляю пользовательские контакты к iPhone MapKit?

Я проверяю платформу MapKit на iPhone и очень хотел бы переключить стандартный контакт, который отображает местоположение к изображению, названному "location.png".

Как я могу изменить свой код для разрешения этого?

Maincontroller

- (void)viewDidLoad
{
    [super viewDidLoad];

    //
    // Set the map center
    //
    CLLocationCoordinate2D coordinate;
    coordinate.latitude = 49.2802;
    coordinate.longitude = -123.1182;
    mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000);

    //
    // Set 10 random locations on the map for testing purposes
    //
    for(int i = 0; i < 10; i++)
    {
        CGFloat latDelta = rand()*.035/RAND_MAX -.02;
        CGFloat longDelta = rand()*.03/RAND_MAX -.015;

        CLLocationCoordinate2D newCoord = { coordinate.latitude + latDelta, coordinate.longitude + longDelta };
        MapAnnotation* annotation = [[MapAnnotation alloc] initWithCoordinate:newCoord];
        [mapView addAnnotation:annotation];
        [annotation release];
    }

    [mapView setDelegate:self];
}

MapAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapAnnotation : NSObject <MKAnnotation> {
    CLLocationCoordinate2D _coordinate;
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end

MapAnnotation.m

#import "MapAnnotation.h"

@implementation MapAnnotation
@synthesize coordinate = _coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate
{
    self = [super init];

    if (self != nil)
    {
        _coordinate = coordinate;
    }

    return self;
}

@end

Спасибо!

15
задан Christoffer 23 April 2010 в 14:06
поделиться

2 ответа

Я решил это после просмотра исходного кода MapCallouts

Вот мое решение:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"location.png"];
    annotationView.annotation = annotation;

    return annotationView;
}
25
ответ дан 1 December 2019 в 02:01
поделиться

Посмотрите пример кода MapCallouts, там есть настраиваемый пин с изображением.

http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html

Обратите внимание, что если вы тестируете OS 3.0, вам нужно закомментировать одну строку кода. (он не будет построен, пока вы этого не сделаете).

2
ответ дан 1 December 2019 в 02:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: