-1
我需要更改顏色並在某些位置需要爲註釋點設置圖像。我的代碼只顯示紅色標註請指導我我的代碼是波紋管,請指導我在MkMap中更改註釋的顏色和設置圖像
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//MAP VIEW WebService
// NSLog(@"%@",nam2);
NSString *urlMapString=[NSString stringWithFormat:@"http://www.tranzlogix.com/tranzlogix_webservice/map.php?format=json&truckno=%@",nam2];
NSURL *urlMap=[NSURL URLWithString:urlMapString];
NSData *dataMap=[NSData dataWithContentsOfURL:urlMap];
NSError *errorMap;
NSDictionary *jsonMap = [NSJSONSerialization JSONObjectWithData:dataMap options:kNilOptions error:&errorMap]; NSArray *resultsMap = [jsonMap valueForKey:@"posts"];
NSArray *resMap = [resultsMap valueForKey:@"post"];
NSArray *latitudeString=[resMap valueForKey:@"latitude"];
// NSLog(@"%@", latitudeString);
NSString *latOrgstring = [latitudeString objectAtIndex:0];
// NSLog(@"%@", latOrgstring);
double latitude=[latOrgstring doubleValue];
NSArray *longitudeString=[resMap valueForKey:@"longitude"];
// NSLog(@"%@", longitudeString);
NSString *longOrgstring = [longitudeString objectAtIndex:0];
// NSLog(@"%@", longOrgstring);
double longitude=[longOrgstring doubleValue];
// NSLog(@"latdouble: %f", longitude);
//MAP VIEW Point
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
center.latitude=latitude;
center.longitude=longitude;
//Span
MKCoordinateSpan span;
span.latitudeDelta=THE_SPAN;
span.longitudeDelta=THE_SPAN;
myRegion.center=center;
myRegion.span=span;
//Set our mapView
[MapViewC setRegion:myRegion animated:YES];
//Annotation
//1.create coordinate for use with the annotation
CLLocationCoordinate2D wimbLocation;
wimbLocation.latitude=latitude;
wimbLocation.longitude=longitude;
Annotation * myAnnotation= [Annotation alloc];
CLLocation *someLocation=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:someLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary];
// NSLog(@"%@",dictionary);
addressOutlet=[dictionary valueForKey:@"Street"];
// NSLog(@"%@",addressOutlet);
City=[dictionary valueForKey:@"City"];
// NSLog(@"%@",City);
State=[dictionary valueForKey:@"State"];
// NSLog(@"%@",State);
myAnnotation.coordinate=wimbLocation;
if (addressOutlet!=NULL&&City!=NULL)
{
myAnnotation.title=addressOutlet;
myAnnotation.subtitle=[NSString stringWithFormat:@"%@,%@", City, State];
}
else if (addressOutlet==NULL&&City!=NULL)
{
myAnnotation.title=City;
myAnnotation.subtitle=[NSString stringWithFormat:@"%@,%@", City, State];
}
else if (addressOutlet!=NULL&&City==NULL)
{
myAnnotation.title=addressOutlet;
myAnnotation.subtitle=[NSString stringWithFormat:@"%@", State];
}
else if(addressOutlet==NULL&&City==NULL)
{
myAnnotation.title=State;
myAnnotation.subtitle=[NSString stringWithFormat:@"%@",State];
}
[self.MapViewC addAnnotation:myAnnotation];
}];
}
請指引我,我是很新的Xcode的& Objective-C的