iphone - 在 iPhone map 上绘制路径

标签 iphone objective-c

我正在使用 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/

相关文章:

ios - 使用核心动画对轨迹变化进行动画处理

objective-c - 如何构建Apple的Son ofgrab示例?

iphone - 区分 iPhone 3G 和 iPhone 3GS

iphone - 在 iPhone 应用程序中使用 REST API 时的安全性

ios - SPTTrack trackWithURI 问题

iphone - 从 ViewController 设置 UIImageView 图像

ios - 如何在 Xcode 的 AppDelegate 下创建一个循环?

iphone - Objective-C 中的时间戳

iphone - 在 pushViewController 动画期间避免 UIBarButtonItem 淡出/淡入

iphone - 如何读取 Xcode 控制台输出?