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

    NSArray *locations = [NSArray arrayWithObjects:[[CLLocation alloc] initWithLatitude:28.6667 longitude:77.2167],nil
                          ];
    RMMarker *marker =  [[RMMarker alloc] initWithMapBoxMarkerImage:@"bus" tintColor:[UIColor blueColor]];
    marker.canShowCallout = YES;
    marker.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"depot.jpg"]];
    marker.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    RMShape *shape = [[RMShape alloc] initWithView:mapView1];
    shape.lineColor = [UIColor redColor];
    shape.zPosition =1;

    if ([annotation isKindOfClass:[RMAnnotation class]]) {
        if ([annotation.annotationType isEqualToString:@"marker"]) {
            //[marker replaceUIImage:[self imageWithImage:[UIImage imageNamed:@"ic_marker.png"] scaledToSize:CGSizeMake(32, 48)]];
            [marker setAnchorPoint:CGPointMake(0, 0)];
            return marker;
        } else if ([annotation.annotationType isEqualToString:@"path"]) {
            shape.lineWidth = 3;
            for (int i=0; i<[locations count]; i++) {
                NSLog(@"my coord count : %d", [locations count]);
                CLLocationCoordinate2D myLoc = [[locations objectAtIndex:i] coordinate];
                if (i>0) {
                    [shape addLineToCoordinate:myLoc];
                } else {
                    [shape moveToCoordinate:myLoc];
                }
            }

            [shape closePath];
            return shape;
        }
    } 
    return nil;

}

- (void)mapView:(RMMapView *)mv didUpdateUserLocation:(RMUserLocation *)userLocation{

    CLLocationCoordinate2D userCoordinate = userLocation.location.coordinate;

    CGFloat latDelta = rand()*.035/RAND_MAX -.02;
    CGFloat longDelta = rand()*.03/RAND_MAX -.015;
    CLLocationCoordinate2D newCoord = { userCoordinate.latitude + latDelta, userCoordinate.longitude + longDelta };

   annotation01 = [RMAnnotation annotationWithMapView:mapView coordinate:newCoord andTitle:@"Current Location"];
    annotation01.annotationIcon = [UIImage imageNamed:@"marker-red.png"];
    annotation01.anchorPoint = CGPointMake(0.5, 1);
    annotation01.annotationType = @"marker";
    [mv addAnnotation:annotation01];
}
4

0 回答 0