皆様、こんにちは
MKPointAnnotations のピンの色を変更しようとしています。私が従おうとしたコード例のほとんどは、複雑すぎて従うことができません。私はこれを思いついた:
//
// ViewController.m
// PlayingWithMaps
//
// Created by custom on 22/09/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotationPoint
{
static NSString *annotationIdentifier = @"annotationIdentifier";
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotationPoint reuseIdentifier:annotationIdentifier];
pinView.pinColor = MKPinAnnotationColorPurple;
return pinView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// First, choose what type of map
//mapView.mapType = MKMapTypeHybrid;
mapView.mapType = MKMapTypeStandard;
// Second, where is the centre of the map
CLLocationCoordinate2D centreCoord = {.latitude = -37.123456, .longitude = 145.123456};
MKCoordinateSpan mapSpan = {.latitudeDelta = 0.001, .longitudeDelta = 0.001};
MKCoordinateRegion region = {centreCoord, mapSpan};
[mapView setRegion:region];
// Now lets make a single annotation.
CLLocationCoordinate2D annotationCoordinate;
annotationCoordinate.latitude = -37.781650;
annotationCoordinate.longitude = 145.076116;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
annotationPoint.coordinate = annotationCoordinate;
annotationPoint.title = @"My point of interest";
annotationPoint.subtitle = @"Location";
[mapView addAnnotation:annotationPoint];
// Read a set of points from files into arrays
NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"latitudes" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
NSMutableArray *latitudeStringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByString:@"\n"]];
fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"longitudes" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
NSMutableArray *longitudeStringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByString:@"\n"]];
// Now lets put them onto the map
int i; // Loop control
for (i=0; i<25; i++)
{
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
annotationCoordinate.latitude = [[latitudeStringsArray objectAtIndex:i]floatValue];
annotationCoordinate.longitude = [[longitudeStringsArray objectAtIndex:i]floatValue];
annotationPoint.coordinate = annotationCoordinate;
annotationPoint.title = [NSString stringWithFormat:@"Point %d",i];
annotationPoint.subtitle = [NSString stringWithFormat:@"%f, %f",[[latitudeStringsArray objectAtIndex:i]floatValue],[[longitudeStringsArray objectAtIndex:i]floatValue]];
[mapView addAnnotation:annotationPoint];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
@end
ポイントは適切な場所に表示されますが、デフォルトの赤であり、私が達成しようとしていた紫ではありません。私が行った読書からの私の理解は、注釈ポイントが作成されるたびに (MKAnnotationView) メソッドを呼び出す必要があるということですが、それは起こっていません。
私が欠けているのは基本的なものであることは知っていますが、何がわかりません。
すべての支援に感謝します。
乾杯、