2013-03-13 6 views
1

좌표 배열을 사용하여 mapview를 표시하려고합니다. 그래서 위도와 경도는 배열에 포함되어 있습니다. 그것은 완벽하게 보이고 있습니다. 자, 난 하나의 paritcular 위도 & 다른 색상 핀으로 경도를 표시하고 싶습니다. 내가 참조한 this answer 같은 다른 나는 볼 수 없습니다.지도 뷰 핀의 두 가지 색상을 플롯

ViewController.m


-(void)showMap: 
{ 
... 
... 
DataProvider *d = [DataProvider getInstance]; 
NSInteger numb = sender.view.tag; 
d.colorlatitude = [[arraxy objectAtIndex:numb] objectForKey:@"lat"]; 
d.colorlongitude = [[arraxy objectAtIndex:numb] objectForKey:@"lng"]; 
[d._address removeAllObjects]; 
[arraxy removeObjectAtIndex:sender.view.tag]; 
d._address = arraxy; 

MapViewController *map = [[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil]; 
[self.navigationController pushViewController:map animated:YES]; 

} 

MapViewController.m


-(void)viewWillAppear:(BOOL)animated 
{ 
DataProvider *d = [DataProvider getInstance]; 
[_mapView removeAnnotations:_mapView.annotations]; 

RegisterViewController *appDelegate = [[RegisterViewController alloc]init]; 

[_mapView setShowsUserLocation:YES]; 
[_mapView setRegion:MKCoordinateRegionMakeWithDistance([appDelegate.locationManager location].coordinate, 1000, 1000)]; 
[_mapView setUserTrackingMode:MKUserTrackingModeNone]; 

MKCoordinateRegion rregion = {{0.0,0.0},{0.0,0.0}}; 
rregion.center.latitude = [d.colorlatitude floatValue]; 
rregion.center.longitude = [d.colorlongitude floatValue]; 
rregion.span.latitudeDelta=0.001f; 
rregion.span.longitudeDelta=0.001f; 
[_mapView setRegion:rregion]; 

MapviewAnnotations *add = [[MapviewAnnotations alloc]init]; 
add.coordinate = rregion.center; 
[_mapView addAnnotation:add]; 


if (d._address) 
{ 
    for (int i=0; i<[d._address count]; i++) 
    { 
     NSDictionary *dic=[d._address objectAtIndex:i]; 
     MKCoordinateRegion region={{0.0,0.0},{0.0,0.0}}; 
     region.center.latitude=[[dic objectForKey:@"lat"]floatValue]; 
     region.center.longitude=[[dic objectForKey:@"lng"]floatValue]; 
     region.span.latitudeDelta=0.001f; 
     region.span.longitudeDelta=0.001f; 
     [_mapView setRegion:region]; 

     MapviewAnnotations *ann=[[MapviewAnnotations alloc]init]; 
     ann.coordinate=region.center; 
     [_mapView addAnnotation:ann]; 
    } 
} 
[super viewWillAppear:YES]; 
} 

MKMapView의 대리자 메서드는

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
if (![annotation isKindOfClass:[MapviewAnnotations class]]) 
{ 
    return nil; 
} 

static NSString *reuseId = @"currentloc"; 

MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId]; 
if (annView == nil) 
{ 
    annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId]; 
    annView.animatesDrop = NO; 
    annView.canShowCallout = YES; 
    annView.calloutOffset = CGPointMake(-5, 5); 
} 
else 
{ 
    annView.annotation = annotation; 
} 

DataProvider *mvAnn = [DataProvider getInstance]; 
if (mvAnn.colorlatitude) // here i'm checking the condition. 
{ 
    annView.pinColor = MKPinAnnotationColorGreen; 
} 
else 
{ 
    annView.pinColor = MKPinAnnotationColorRed; 
} 

return annView; 
} 
입니다

좌표가 녹색 인 경우 해당 좌표에만 녹색 핀을 그려야합니다. 이것을 달성하는 방법?

+0

핀 이미지 [annView setImageName : @ "pin-green.png"]; – Pratik

+0

@Pratik 나는 그것을 시도했다. 그 일. 그러나 나는 그것을 특정 위도와 경도의 좌표로 나타내려고합니다. – Praveenkumar

+0

나중에하지만 두 개의 다른 색상 핀을 하나의 OS를 빨간색과 하나의 녹색을 사용하고 다른 경우 조건을 넣어 – Pratik

답변

0

에 투입할지 결정하는 당신이 그리고있는 무엇을 말할 필요가 내 viewWillAppear 내가받은 DataProvider에서 좌표를 지정하고 플래그가있는 MapviewAnnotations을 지정하고 간단하게 세 가지 유형의 핀으로 구분합니다.

건배!

1

코드와 히나타가 언급 한 것과 다른 점은 다른 코드의 if 문이 현재 사용중인 색상을 결정하기 위해 현재 드로잉하고있는 주석에 값 (yesno)을 사용한다는 것입니다. DataProvider에서 값을 얻지 만 그리는 주석이 무엇인지 알려주지 않으므로이 예제는 사용자가지도를 핀을 요청할 때 instance 메서드가 반환하는 것과 같은 느낌을줍니다. 당신은 그것에서 나는 내 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

MapviewAnnotations *mvAnn = (MapviewAnnotations *)annotation; 
if (mvAnn.flag == 1) 
{ 
    annView.pinColor = MKPinAnnotationColorGreen; 
} 
else if (mvAnn.flag == 10) 
{ 
    annView.pinColor = MKPinAnnotationColorPurple; 
} 
else 
{ 
    annView.pinColor = MKPinAnnotationColorRed; 
} 

의 내부에 아래와 같은 몇 가지 플래그를 통해 이런 짓을 한 colorlatitude

관련 문제