我試圖在提供的地圖應用程序中顯示具有多個點的路線。在iOS中繪製具有多個點的路線
我已經想出瞭如何在this post之後的兩點之間顯示路線。我正在建立一個these directions以下的多個點的列表。
據我所知,打開maps.google.com(在iOS中)將打開地圖應用程序(如果地圖不可用,則爲Safari)。
結果是地圖應用程序仍然只顯示開始和目的地之間的路線。沒有顯示與mrad
參數相加的點數。
是否可以在iOS中顯示具有多個目的地的路線(無需構建我自己的映射系統)?
我試圖在提供的地圖應用程序中顯示具有多個點的路線。在iOS中繪製具有多個點的路線
我已經想出瞭如何在this post之後的兩點之間顯示路線。我正在建立一個these directions以下的多個點的列表。
據我所知,打開maps.google.com(在iOS中)將打開地圖應用程序(如果地圖不可用,則爲Safari)。
結果是地圖應用程序仍然只顯示開始和目的地之間的路線。沒有顯示與mrad
參數相加的點數。
是否可以在iOS中顯示具有多個目的地的路線(無需構建我自己的映射系統)?
對於你的問題,答案是肯定的。
但我會停止嘗試在那裏看起來聰明。你看着錯誤的SO問題和答案。你所尋找的是一個兩個步驟:
幸運的是,顯然有一個Github項目可以滿足您的需求。我沒有使用它,所以我不知道它的質量,但肯定比我在這裏解釋如何做到這一點。
https://github.com/kishikawakatsumi/MapKit-Route-Directions
我勸你看看吧。
這裏是簡單和容易的代碼通過多個位置,可以連接路徑一小部分。 獲得完整的項目只是去導通https://github.com/vikaskumar113/RouteWithMultipleLocation
NSArray *dictionary = @[
@{
@"Source_lat": @"28.6287",
@"Source_lon": @"77.3208",
@"Dest_lat": @"28.628454",
@"Dest_lon": @"77.376945",
@"S_address": @"Vaishali,Delhi",
},
@{
@"Source_lat": @"28.628454",
@"Source_lon": @"77.376945",
@"Dest_lat": @"28.5529",
@"Dest_lon": @"77.3367",
@"S_address": @"Noida Sec 63",
},
@{
@"Source_lat": @"28.5529",
@"Source_lon": @"77.3367",
@"Dest_lat": @"28.6276",
@"Dest_lon": @"77.2784",
@"S_address": @"Noida Sec 44",
},
@{
@"Source_lat": @"28.6276",
@"Source_lon": @"77.2784",
@"Dest_lat": @"28.6287",
@"Dest_lon": @"77.3208",
@"S_address": @"Laxmi Nagar,Delhi",
},
];
for (int i=0; i<dictionary.count; i++) {
NSDictionary*dict=[dictionary objectAtIndex:i];
NSString*S_lat=[dict valueForKey:@"Source_lat"];
NSString*S_lon=[dict valueForKey:@"Source_lon"];
NSString*D_lat=[dict valueForKey:@"Dest_lat"];
NSString*D_lon=[dict valueForKey:@"Dest_lon"];
NSString*address=[dict valueForKey:@"S_address"];
NSString* apiUrlStr =[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@,%@&destination=%@,%@&sensor=false",S_lat,S_lon, D_lat, D_lon
];
NSData *data =[NSData dataWithContentsOfURL:[NSURL URLWithString:apiUrlStr]];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
CLLocationCoordinate2D coord;
coord.latitude=[S_lat floatValue];
coord.longitude=[ S_lon floatValue];
MKCoordinateRegion region1;
region1.center=coord;
region1.span.longitudeDelta=0.2 ;
region1.span.latitudeDelta=0.2;
[theMapView setRegion:region1 animated:YES];
MKPointAnnotation *sourceAnnotation = [[MKPointAnnotation alloc]init];
sourceAnnotation.coordinate=coord;
sourceAnnotation.title=address;
[theMapView addAnnotation:sourceAnnotation];
}
我敢肯定,這是對服務條款使用谷歌API的方向的蘋果地圖上。 :( – deepwinter
這是一個老問題,今天在iOS7上你有MKDirections。 –