2011-09-19 36 views
2

我想添加註釋到地圖上2個位置之間的路線。該註釋就像Google Map中的複選標記。我使用MKPolyline繪製了路線。現在添加幾個註釋,我應該怎麼做?在iPhone中的地圖中添加路線註釋

是新手。所以請不要介意我問這個問題。

在此先感謝。

回答

2

因爲,我認爲這是一個很好的問題,許多人都面臨這個問題,我正在回答。 我們需要實現的MKAnnotationView此委託方法..

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 

而且我們需要所有的註釋中是這樣的路線數組..

self.mRouteArray = [mDirections routeArray]; 
    NSArray *_routeWayPoints1 = [[mRouteArray objectAtIndex:0] wayPoints]; 
    NSArray *mPlacetitles = [[mRouteArray objectAtIndex:0] mPlaceTitle]; 

    for(int idx = 0; idx < [_routeWayPoints1 count]; idx++) 
    { 
     mBetweenAnnotation = [[SBRouteAnnotation alloc] initWithCoordinate:[[_routeWayPoints1 objectAtIndex:idx]coordinate] 
                    title:[mPlacetitles objectAtIndex:idx] 
                 annotationType:SBRouteAnnotationTypeWayPoint]; 

     [self.mAnnotations addObject:mBetweenAnnotation]; 
     [mBetweenAnnotation release]; 
    } 

這將加載所有註釋之間的路線。 可能這會幫助他人.. 快樂編碼...