2014-05-23 52 views
0

我的應用程序允許顯示蘋果地圖,引腳位置和查找最短路線,從兩點畫線。我知道在地圖上繪製線條的方式,但我不知道如何在繪製兩點之間找到點的數組。 對我有什麼建議嗎?我不使用谷歌地圖API。 謝謝。從iOS中的兩個點查找方向6

回答

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]; 
} 

}];