我正在使用 Route-Me iPhone 的库。例如,我的问题是我想在 map 上绘制一条路径。
我在达拉斯,我想去纽约,然后我会在这两个地方放置标记,然后在这两个标记之间绘制路径。
任何人都可以建议我如何做到这一点。
如果有任何其他 Map 而不是 RouteMe 也可以。
最佳答案
以下代码将绘制两点之间的路径。 (在您的情况下,您必须添加所有路线点)
// 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;
关于iphone - 在 iPhone map 上绘制路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/790313/