iCoder4777
iCoder4777

Reputation: 1692

adding annotations in the route in a Map in iPhone

I want to add annotations to a route between 2 locations on the map. That annotation would be like checkmark in Google Map. I have drawn route using MKPolyline. Now to add several annotations what should I do?

Am a newbie. so please dont mind me asking this question.

Thanks in advance.

Upvotes: 2

Views: 539

Answers (1)

iCoder4777
iCoder4777

Reputation: 1692

As, I think that this was a good question and many have faced this, I am giving its answer. We need to implement this delegate method of MKAnnotationView..

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

Also we need to have an array of all the annotation in the route like this..

    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];
    }

this will load all the annotations between the route. May this will help others.. Happy Coding...

Upvotes: 2

Related Questions