我的应用程序允许显示Apple Map,引脚位置和查找最短路线,从两点画线。我知道在地图上绘制线条的方法,但我不知道如何在两点之间找到要绘制的点数组。 对我有什么建议吗?我没有使用谷歌地图API。 感谢。
答案 0 :(得分:0)
如果使用iOS7,您可以获得如下路线:
// start and end point coordinates
CLLocationCoordinate2D *startPoint = CLLocationCoordinate2DMake(53.3478, -6.2597);
CLLocationCoordinate2D *endPoint = CLLocationCoordinate2DMake(53.2178, -6.6637);
// create a placemark and map item for your start point
MKPlacemark *startPlacemark = [[MKPlacemark alloc]initWithCoordinate:startPoint addressDictionary:nil];
MKMapItem *startMapItem = [[MKMapItem alloc]initWithPlacemark:startPlacemark];
// create a placemark and map item for your end point
MKPlacemark *endPlacemark = [[MKPlacemark alloc]initWithCoordinate:endPoint addressDictionary:nil];
MKMapItem *endMapItem = [[MKMapItem alloc]initWithPlacemark:endPlacemark];
// create your directions request
MKDirectionRequest *request = [[MKDirectionRequest alloc]init];
request.source = startMapItem;
request.destination = endMapItem;
request.requestAlternateRoute = NO; // or you can set this to YES if you wish
// get your directions
MKDirections *directions = [[MKDirections alloc]initWithRequest:request];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error){
if(response.routes.count)
{
MKRoute *route = [response firstObject];
[mapView addPolyline:route.polyline level:MKOverlayLevelAboveRoads];
}
}];