2009-04-26 9 views
5

Estoy usando la biblioteca Route-Me para el iPhone. Mi problema es que quiero dibujar un camino en el mapa, por ejemplo.dibujar ruta en el mapa en iphone

Estoy en Dallas y quiero ir a Nueva York, entonces solo voy a poner marcador en estos dos lugares y el camino se dibujará entre estos dos marcadores.

¿Puede algún cuerpo sugerirme cómo se puede hacer esto?

Si hay otro mapa en lugar de RouteMe, entonces también está bien.

Respuesta

0

Disculpa, no he visto nada como esto, solo señalaría que si las personas te votan porque creen que estás hablando de las nuevas funciones de mapeo del SDK, vuelve a leer tu pregunta en donde hablas de un biblioteca de terceros (posiblemente sea una necesidad válida ya que no puede hacer indicaciones paso a paso con el mapa oficial SDK).

4

Route-me tiene una clase RMPath para este propósito. ¿Has jugado con eso? Si es así, ¿qué hiciste, qué hizo y qué no funcionó?

7

El siguiente código dibujará la ruta entre 2 puntos. (En su caso hay que añadir todos los puntos de ruta)

// Set map view center coordinate 
CLLocationCoordinate2D center; 
center.latitude = 47.582; 
center.longitude = -122.333; 
slideLocation = center; 
[mapView.contents moveToLatLong:center]; 
[mapView.contents setZoom:17.0f]; 

// Add 2 markers(start/end) and RMPath with 2 points 
RMMarker *newMarker; 
UIImage *startImage = [UIImage imageNamed:@"marker-blue.png"]; 
UIImage *finishImage = [UIImage imageNamed:@"marker-red.png"]; 
UIColor* routeColor = [[UIColor alloc] initWithRed:(27.0 /255) green:(88.0 /255) blue:(156.0 /255) alpha:0.75]; 
RMPath* routePath = [[RMPath alloc] initWithContents:mapView.contents]; 
[routePath setLineColor:routeColor]; 
[routePath setFillColor:routeColor]; 
[routePath setLineWidth:10.0f]; 
[routePath setDrawingMode:kCGPathStroke]; 
CLLocationCoordinate2D newLocation; 
newLocation.latitude = 47.580; 
newLocation.longitude = -122.333; 
[routePath addLineToLatLong:newLocation]; 
newLocation.latitude = 47.599; 
newLocation.longitude = -122.333; 
[routePath addLineToLatLong:newLocation]; 
[[mapView.contents overlay] addSublayer:routePath]; 

newLocation.latitude = 47.580; 
newLocation.longitude = -122.333; 
newMarker = [[RMMarker alloc] initWithUIImage:startImage anchorPoint:CGPointMake(0.5, 1.0)]; 
[mapView.contents.markerManager addMarker:newMarker AtLatLong:newLocation]; 
[newMarker release]; 
newMarker = nil; 

newLocation.latitude = 47.599; 
newLocation.longitude = -122.333; 
newMarker = [[RMMarker alloc] initWithUIImage:finishImage anchorPoint:CGPointMake(0.5, 1.0)]; 
[mapView.contents.markerManager addMarker:newMarker AtLatLong:newLocation]; 
[newMarker release]; 
newMarker = nil; 
3

Ruta-Me cómo dibujar un recorrido sobre el mapa, por ejemplo, no exactamente, pero cerca.

Uso RMPath dibujar un polígono en la capa de superposición

//polygonArray is a NSMutableArray of CLLocation 
- (RMPath*)addLayerForPolygon:(NSMutableArray*)polygonArray toMap:(RMMapView*)map { 
    RMPath* polygonPath = [[[RMPath alloc] initForMap:map] autorelease]; 
    [polygonPath setLineColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]]; 
    [polygonPath setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]]; 
    [polygonPath setLineWidth:1]; 

    BOOL firstPoint = YES; 
    for (CLLocation* loc in polygonArray) { 
     if (firstPoint) { 
      [polygonPath moveToLatLong:loc.coordinate]; 
      firstPoint = NO; 
     } else { 
      [polygonPath addLineToLatLong:loc.coordinate]; 
     } 
    } 

    [polygonPath closePath]; 

    polygonPath.zPosition = -2.0f; 

    NSMutableArray *sublayers = [[[[mapView contents] overlay] sublayers] mutableCopy]; 
    [sublayers insertObject:polygonPath atIndex:0]; 
    [[[mapView contents] overlay] setSublayers:sublayers]; 
    return polygonPath; 
} 

Nota:

La última RouteMe tiene addLineToCoordinate: (CLLocationCoordinate2D) en lugar de coordinar addLineToLatLong.

Esto es más reciente que se encuentra en el MapTestBed en el ejemplo de la Ruta-me

- (RMMapLayer *)mapView:(RMMapView *)aMapView layerForAnnotation:(RMAnnotation *)annotation 
{ 
    if ([annotation.annotationType isEqualToString:@"path"]) { 
     RMPath *testPath = [[[RMPath alloc] initWithView:aMapView] autorelease]; 
     [testPath setLineColor:[annotation.userInfo objectForKey:@"lineColor"]]; 
     [testPath setFillColor:[annotation.userInfo objectForKey:@"fillColor"]]; 
     [testPath setLineWidth:[[annotation.userInfo objectForKey:@"lineWidth"] floatValue]]; 

     CGPathDrawingMode drawingMode = kCGPathStroke; 
     if ([annotation.userInfo containsObject:@"pathDrawingMode"]) 
      drawingMode = [[annotation.userInfo objectForKey:@"pathDrawingMode"] intValue]; 
     [testPath setDrawingMode:drawingMode]; 

     if ([[annotation.userInfo objectForKey:@"closePath"] boolValue]) 
      [testPath closePath]; 

     for (CLLocation *location in [annotation.userInfo objectForKey:@"linePoints"]) 
     { 
      [testPath addLineToCoordinate:location.coordinate]; 
     } 

     return testPath; 
    } 
    if ([annotation.annotationType isEqualToString:@"marker"]) { 
     return [[[RMMarker alloc] initWithUIImage:annotation.annotationIcon anchorPoint:annotation.anchorPoint] autorelease]; 
    } 

    return nil; 
} 
Cuestiones relacionadas