2016-10-17 55 views
0

在我的應用程序中,我得到了來自Parse查詢的一些其他數據的經緯度。然而,只有大約100個註釋被添加,當應該有156個時。我在控制檯中驗證它正在獲取地圖上缺失部分的座標,它只是不會爲它們添加註釋。我錯過了明顯的東西嗎?iOS MapKit註解並非全部添加

-(void) viewWillAppear:(BOOL)animated { 
CLLocationCoordinate2D coord = {.latitude = 15.8700320, .longitude = 100.9925410}; 
MKCoordinateSpan span = {.latitudeDelta = 3, .longitudeDelta = 3}; 
MKCoordinateRegion region = {coord, span}; 
[mapViewUI setRegion:region]; 
PFQuery *query = [PFQuery queryWithClassName:@"Share"]; 
    [query setLimit:1000]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
if (!error) { 
self.mapViewData = objects; 
    NSLog(@"HOW MANY ARE THERE %lu", (unsigned long)[objects count]); 
for (int i=0;i<[objects count];i++) 
{ 
// Question * q = [[Question alloc]init]; 

PFObject * obj = [self.mapViewData objectAtIndex:i]; 
NSLog(@"%@", obj); 
self.theObject = obj; 

NSString *string = obj[@"WhereAt"]; 


NSArray *stringArray = [string componentsSeparatedByString: @","]; 

CLLocationDegrees myLatitude = [[stringArray objectAtIndex:0] doubleValue]; 
CLLocationDegrees myLongitude = [[stringArray objectAtIndex:1] doubleValue]; 
CLLocationCoordinate2D coord2 = {.latitude = myLatitude, .longitude = myLongitude}; 
    NSLog(@"LATITUDE %@", [stringArray objectAtIndex:0]); 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
dateFormatter.dateFormat = @"MMM dd, yyyy"; 

MKPointAnnotation *annotation2 = [[MKPointAnnotation alloc] init]; 
[annotation2 setCoordinate:coord2]; 
[annotation2 setTitle:obj[@"FamilyName"]]; 
[annotation2 setSubtitle:obj[@"Result"]]; 

[mapViewUI addAnnotation:annotation2]; 


} 


} else { 
// Log details of the failure 
NSLog(@"Error: %@ %@", error, [error userInfo]); 
} 


}]; 
} 
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
    if (annotation == mapViewUI.userLocation) 
    { 
     return nil; 
    } 
    else 
    { 

    MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] init]; 

    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    dateFormatter.dateFormat = @"MMM dd, yyyy"; 

    if ([annotation.subtitle isEqualToString:@"Accepted Bible"]) { 
     NSLog(@"Accepted"); 
     annotationView.pinTintColor = [UIColor greenColor]; 

    } 
    else if ([annotation.subtitle isEqualToString:@"Requested Different Material"]) { 
     NSLog(@"Different"); 

     annotationView.pinTintColor = [UIColor blackColor]; 

    } 
    else if ([annotation.subtitle isEqualToString:@"Not Home"]) { 
     NSLog(@"Not Home"); 

     annotationView.pinTintColor = [UIColor yellowColor]; 

    } 
    else if ([annotation.subtitle isEqualToString:@"Rejected Bible"]) { 
     NSLog(@"Rejected"); 

     annotationView.pinTintColor = [UIColor redColor]; 

    } 



    return annotationView; 
    } 

    return nil; 
} 

回答

0

我不知道這是不是你的問題的原因,但你應該是「再造」註釋觀點是這樣的:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ClubPinAnnotation *)annotation { 

    MKAnnotationView *pinView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MyPinIdentifier"]; 

    if (!pinView) { 
     pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPinIdentifier"]; 
    } else {  
     pinView.annotation = annotation; 
    } 

    // Set up the pin view properties 

    return pinView; 
} 

此外,檢查您的緯度/多頭是正確的。地圖視圖只會調用當前視圖實際需要的視圖視圖,所以如果您有一些視圖(例如(0,0)),它們將不會顯示,直到您縮小以包含非洲海岸。

+0

這樣做實際上使情況變得更糟......沒有一種顏色是正確的,並且仍有許多缺失的註釋。 –