Domanda

I have a problem when trying to add a polyline on the map. I get directions from MKDirections, and create a RMPolylineAnnotation, but it does not appear on the map.
As I can see, the following method is called just once when the map appears:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation 

Here is the code I am using:

- (void)getRoute {
CLLocation *source = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude];

CLLocation *destination = [[CLLocation alloc] initWithLatitude:self.mapView.selectedAnnotation.coordinate.latitude longitude:self.mapView.selectedAnnotation.coordinate.longitude];

[AppleDirectionManager getDirectionsFromPoint:source toPoint:destination transportType:MKDirectionsTransportTypeAutomobile withCompletion:^(MKDirectionsResponse *result) {

    self.routeStepsArray = [[result.routes firstObject] steps];
    for (MKRoute *route in result.routes) {
        NSMutableArray *points = [NSMutableArray array];
        for (int i = 0; i < route.polyline.pointCount; i++) {
            MKMapPoint point = route.polyline.points[i];

            CLLocation *location = [[CLLocation alloc] initWithLatitude:point.x longitude:point.y];
            [points addObject:location];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray *arr = [points copy];
            RMPolylineAnnotation *polyline = [[RMPolylineAnnotation alloc] initWithMapView:self.mapView points:arr];
            [self.mapView addAnnotation:polyline];
        });
    }
}];
}

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation {

if (annotation.isUserLocationAnnotation)
    return nil;

RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"blabla.png"]];

[marker setCanShowCallout:YES];

[marker setName:@"blabla"];

return marker;

}

Also I can not show a custom callout for a RMPointAnnotation.

È stato utile?

Soluzione

For RMPointAnnotation it's easily.

 _polylineAnnotation = [[RMPolylineAnnotation alloc] initWithMapView:_mapView points:@[Location,Location]];
 _polylineAnnotation.lineColor = [UIColor redColor];
 _polylineAnnotation.lineWidth = 10.0f;
 [_mapView addAnnotation:_polylineAnnotation];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top