Ich teste das MapKit-Framework auf dem iPhone aus und würde wirklich gerne den Standard-Pin, der einen Ort anzeigt, auf ein Bild namens "location.png" umstellen.Wie füge ich dem iPhone MapKit benutzerdefinierte Pins hinzu?
Wie kann ich meinen Code ändern, um dies zu ermöglichen?
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
Thank you!
es Sie ändern müssen mapView → Karte scheint – Cfr
@Christoffer die Wetterkarte Verbindung unterbrochen wird – Caipivara
Als Alternative zu der Broken WeatherMap Link, ein relevanter Apple Doc: https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotingMaps/Annota tingMaps.html – SimplGy