當刷新完成時,PIn color mapView有問題。 在我的應用程序中,我用兩種顏色顯示某個點,以確定服務是否可用。 第一次啓動時,不會出現問題。該代碼是跟隨者:MapView問題 - 在地圖重新編碼時Pin改變顏色
- (void)viewDidLoad
{
[super viewDidLoad];
[self dowloadPoint]; // here I exucte the first start
}
- (void)dowloadPoint{
NSURL *url1 =[NSURL URLWithString:@"http:MYUSRL"];
NSData *datos1 =[[NSData alloc] initWithContentsOfURL:url1];
[self plotBarPosition:datos_string1]; //Here I call the plotBarPosition method
}
- (void)plotBarPosition:(NSString *)datos_string1 {
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
// Parse the string into JSON
NSDictionary *json = [(NSDictionary*)[datos_string1 JSONValue]objectForKey:@"features"];
// Get the objects you want, e.g. output the second item's client id
NSArray *items_properties = [json valueForKeyPath:@"properties"];
NSArray *items_geo = [json valueForKeyPath:@"geometry"];
for (int i = 0; i < [json count]; i++){
NSString *nomprePunto =[[items_properties objectAtIndex:i] objectForKey:@"title"];
NSNumber *lat =[[[items_geo objectAtIndex:i] objectForKey:@"coordinates"] objectAtIndex:0];
NSNumber *lon =[[[items_geo objectAtIndex:i] objectForKey:@"coordinates"] objectAtIndex:1];
CLLocationCoordinate2D coordinate;
coordinate.latitude = lat.doubleValue;
coordinate.longitude = lon.doubleValue;
//ESTADO
NSString *description = [[items_properties objectAtIndex:i] objectForKey:@"description"];
NSString *estado_punto = [[NSString alloc]init];
if ([description rangeOfString:@"Averiado"].location == NSNotFound) {
estado_punto = @"Available";
} else {
estado_punto = @"NOt Available";
averiados ++;
}
NSString *averiadosStr = [NSString stringWithFormat:@"%d",averiados];
averiadosLabel.text = averiadosStr;
MyLocation *location =[[MyLocation alloc] initWithName:nomprePunto coordinate:coordinate estado:estado_punto];
[_mapView addAnnotation:location];
}
}
- (MKPinAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(MyLocation *)annotation {
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MyLocation class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
if([[annotation estado] isEqualToString:@"En Servicio"])
annotationView.pinColor = MKPinAnnotationColorGreen;
} else {
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
但磨片我添加refres按鈕是功能僅僅是一個refreshcalling的dowloadPoint再次
- (IBAction)refresh{
[self dowloadPoint];
}
銷的顏色「隨機方式」改變,而不是與真實的觀點相符合。 有關正在發生的事情的任何想法?提前致謝。
編輯:seemps pproblems是由於:
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
刪除它,應用程序工作正常,但銷區淹沒abow前面的...:S
嗨。謝謝你的回答。我使用ARC所以問題不依賴於發佈,是嗎? – doxsi 2013-03-27 15:36:35
嗨,我只有一個更多的想法:MKAnnotationView類參考的文檔說它的註釋屬性:「你不應該直接改變這個屬性的值。」但是,您在聲明annotationView.annotation = annotation;中執行此操作。也許這會導致問題? – 2013-03-27 19:39:23
這個問題似乎是由於使用了:for(idmap_annotations中的註解)。 }如果我刪除它可以正常工作,但引腳被淹沒在以前的引腳之上。 – doxsi 2013-03-27 20:58:58