在图钉中放置图钉后,如何更新/更改其颜色?

| 我正在做一个贴文,将图钉/注释放在mapview中。当用户接近别针时,我希望别针改变颜色。一切正常,将销钉放置在我想要的位置,当距离足够近时,我会收到一条警报消息。但是我不确定如何更新图钉颜色。我是否需要删除注释并替换它们?似乎不必要,我要寻找的只是某种更新/刷新mapview,而不必替换注释。
CLLocation *place =[[CLLocation alloc] initWithCoordinate:location altitude:1 horizontalAccuracy:1 verticalAccuracy:-1 timestamp:nil];
    AddresAnnotation *ann = [[AddresAnnotation alloc] initWithCoordinate:place.coordinate];
    [ann setTitle:[rows placeName]];
    [mapView addAnnotation:ann];
location是CLLocationCoordinate2D 行是一个包含不同位置及其信息的对象 这是mapView委托方法:(不确定最后一个\“} \”为什么不在代码示例中)
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

    if (annotation != self.mapView.userLocation) {
        annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@\"Plats\"] autorelease];
        [annView setPinColor:MKPinAnnotationColorRed];
        annView.animatesDrop = TRUE;
        annView.canShowCallout = YES;
        return annView;
    } else {
        zoomButton.enabled = TRUE;
        return nil;
    }
}     
已邀请:
您需要制作一个循环,以测试位置是否在用户x英里范围内。这是我在自己的代码中使用的意思的示例
for (CLLocation *prox in locations) {
    NSLog(@\"prox %@\", prox);
    float distanceFromLocation = [mapView.userLocation.location distanceFromLocation:prox]/1609.344;
    NSLog(@\"distance %f\", distanceFromLocation);
    if (distanceFromLocation <= 10) {
        NearbyLocation *nearbyLocation = [[NearbyLocation alloc]init];
        NSString *key = [NSString stringWithFormat:@\"%d\", index];
        nearbyLocation.title = [storedTitles objectForKey:key];
        nearbyLocation.loction = prox;
        nearbyLocation.subtitle = [NSString stringWithFormat:@\"%.1f miles away\", distanceFromLocation];
        nearbyLocation.lat = prox.coordinate.latitude;
        nearbyLocation.lon = prox.coordinate.longitude;
        [newArray addObject:nearbyLocation];
        [nearbyLocation release];
    }
    index++;
}
NSLog(@\"new array %d prox %d\", [newArray count], [proximityOutlet.nearbyLocations count]);
if ([newArray count] > [proximityOutlet.nearbyLocations count]) {
    NSLog(@\"set array\");
    // if the new array has actually added any objects, set the array and switch views;
    proximityOutlet.nearbyLocations = newArray;
    //[self.navigationController pushViewController:proximityOutlet animated:YES];
    proximityOutlet.modalPresentationStyle = UIModalPresentationPageSheet;
    proximityOutlet.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:proximityOutlet animated:YES];
}
[newArray release];

}
基本上,创建一个循环,将搜索一系列位置。有它     [mapView.userLocation.location distanceFrom:prox] /1609.334 // prox表示一个位置实例,该实例经过测试以查看是否在用户的x英里之内。 然后说
if ([mapview.userLocation.location distanceFrom:prox]/1609.334 < (however many miles)){

        annotationView = x;
}
    

要回复问题请先登录注册