2013-05-28 58 views
1

我一直在iOS5中繪製路線,但由於應用程序必須升級到iOS6,因此不允許在座標位置之間繪製路線。我搜查了很多,但最終沒有成功。任何人都可以幫助我哪些api在iOS6中使用,因爲谷歌地圖不支持了嗎?如何在地圖中繪製路線,ios6?

編輯:我已經使用谷歌iOS SDK以前繪製的路線,將自動照顧多義線。據我搜索,我將能夠重定向到瀏覽器顯示路線和導航。但我需要繪製這個應用程序[iOS6]。 iOS6是否會自動執行路由,如果有的話,可以共享一些代碼來獲取它的要點。此代碼示例我在iOS5中使用Google地圖

// over lay map to draw route 
    routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:routeMapView]; 
    diretions = [UICGDirections sharedDirections]; 

    UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init]; 
//setting travel mode to driving 
    options.travelMode = UICGTravelModeDriving; 
    [diretions loadWithStartPoint:startPoint endPoint:endPoint options:options]; 

// Overlay polylines 
    UICGPolyline *polyline = [directions polyline]; 
    NSArray *routePoints = [polyline routePoints]; 
     NSLog(@"routePoints %@",routePoints); 

    [routeOverlayView setRoutes:routePoints]; 
+0

你如何繪製你的路線?因爲雖然Apple在iOS 6中更改了地圖提供程序,但折線的繪製方式幾乎相同。也許提供一些代碼給我們看看? – lxt

+0

更新了我的問題 – sahasra

回答

0

我確實在我的應用程序路線。我使用的谷歌地理編碼API(用於iOS 6中只)https://developers.google.com/maps/documentation/geocoding/

事情是這樣的:

- (void) sendRequestForLat: (CGFloat) lat lon: (CGFloat) lon 
{ 
    NSString* request; 
    NSInteger zoom = 12; 

    NSString* location = [NSString stringWithFormat: @"%f,%f", lat, lon]; 

    NSString* daddr = [NSString stringWithFormat: @"%f,%f", myLat, myLon]; 
    request = [NSString stringWithFormat: @"saddr=%@&daddr=%@&zoom=%i&directionsmode=walking", location, daddr, zoom]; 

    NSString* typeMapsApp = isGoogleMapsAppPresent ? @"comgoogle" : @""; 

    NSString* urlString = [NSString stringWithFormat: @"%@maps://?%@", typeMapsApp, request]; 
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]]; 
} 
0

您使用第三方代碼段來執行路線繪製,而不是使用MapKit本身。您正在使用的庫(我在GitHub here上找到)未更新兩年。

我建議你從圖書館搬到更近的地方。如果你想要的話,你可以考慮使用谷歌的iOS Map SDK,它支持iOS 6(link here)。您可以將其與Google的Directions API結合使用,直接在地圖上繪製折線。或者你可以堅持MKMapView,並再次用多段線直接繪製到地圖上。

這並不是說iOS已經改變了它如何將多義線繪製到地圖上 - 這是因爲您使用的第三方代碼已過時。

+0

如果我在iOS 6中使用Google地圖,我的應用程序會被拒絕嗎? – sahasra

+0

如何結合方向api與谷歌sdk繪製路線的駕駛模式,你可以提供任何代碼鏈接或一些示例代碼? – sahasra