【发布时间】:2013-12-19 11:35:01
【问题描述】:
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationCoordinate2D currentLocation;
currentLocation.latitude = self.mapView.userLocation.location.coordinate.latitude;
currentLocation.longitude = self.mapView.userLocation.location.coordinate.longitude;
CLLocationCoordinate2D otherLocation;
otherLocation.latitude = [lati doubleValue];
otherLocation.longitude = [longi doubleValue];
MKPointAnnotation *mka = [[MKPointAnnotation alloc]init];
mka.Coordinate = otherLocation;
mka.title = @"!";
[self.mapView addAnnotation:mka];
self.mapView.delegate = self;
MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D));
pointsArray[0]= MKMapPointForCoordinate(currentLocation);
pointsArray[1]= MKMapPointForCoordinate(otherLocation);
routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];
free(pointsArray);
[self.mapView addOverlay:routeLine];
}
我正在使用此代码显示坐标之间的折线,但我得到的是这条直线。如何解决此问题。
【问题讨论】:
-
我根本不是 MapKit 方面的专家,但 2 点的折线不是直线吗?你期待什么结果?
-
@MartinR 我想连接这两点。
-
@S.J 那么你的问题是什么?它确实连接了两点!
-
你想得到两点之间的driving路线吗?在 iOS 7 中,使用 MKDirections 提供多条路线的折线。使用该类有一些关于 SO 的答案。
-
我想用折线连接当前位置和其他位置
标签: ios objective-c mkmapview mapkit mkpolyline