在iphone上绘制地图上的路径

5 iphone objective-c

我正在为iPhone 使用Route-Me库.我的问题是我想在地图上画一条路径,例如.

我在达拉斯,我想去纽约,然后我会在这两个地方放置标记,并在这两个标记之间绘制路径.

任何人都可以建议我如何做到这一点.

如果任何其他地图而不是RouteMe,那么也没关系.

Vit*_*y A 7

以下代码将绘制2点之间的路径.(在您的情况下,您必须添加所有路线点)

// 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;
Run Code Online (Sandbox Code Playgroud)


Ken*_*ner 0

抱歉,我没有看到这样的事情 - 我只会注意到,如果人们因为认为您正在谈论新的 SDK 映射功能而对您投反对票,请再次阅读您在谈论第三方库时的问题(仍然可能是一个有效的需求,因为您无法使用官方地图 SDK 进行逐向导航)。