2011-07-11 45 views
4

我通過提供Lat和Source.go的lat長座標來加載google maps在UIWebview中。但問題是顯示的是當它被加載時的行車路線。如果我們希望看到地圖,然後我們必須單擊地址旁邊提供的地圖按鈕。我需要直接顯示地圖,而不是在Web視圖加載時駕駛路線。 任何人都可以告訴我如何實現這一點。UIWebview中的Google地圖直接顯示行車路線而非地圖

UIWebView *webView=[[UIWebView alloc]initWithFrame:webViewRect]; 
       webView.delegate=self; 
       webView.scalesPageToFit=YES; 

       CLLocationCoordinate2D start = { 34.052222, -118.243611 }; 
       CLLocationCoordinate2D destination = { 37.322778, -122.031944 };   
       //NSString *[email protected]"http://maps.google.co.in/"; 

       NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", 
               start.latitude, start.longitude, destination.latitude, destination.longitude]; 
       NSLog(@"URL string-----> %@",googleMapsURLString); 



       NSURL *url=[NSURL URLWithString:googleMapsURLString]; 
       NSURLRequest *requestObj=[NSURLRequest requestWithURL:url]; 
       [webView loadRequest:requestObj]; 
       [self.view addSubview:webView]; 

此外,我想知道如何我通過URL如果我需要說的地方A到B和從B到C.

+0

嘿kamlesh ..我也是做同樣的事情..任何運氣與你? –

+0

沒有太多...不可能 –

+0

爲什麼不使用UIMapView? – Armand

回答

9

去只是改變你的URL行

NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, destination.latitude, destination.longitude]; 

與下面的代碼

NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&output=embed",start.latitude, start.longitude, destination.latitude, destination.longitude]; 

添加的唯一的事情就是output=embed迫使網頁打開該地圖直接不需要打開要求輸入源和目的地的填充輸入框的屏幕。

對於進一步澄清,你還可以檢查出了在谷歌地圖中使用來自Google Map Parameters

上面會解決你的第一個查詢的所有參數。

和關於第二個查詢 即另外我想知道如何我通過URL如果我需要說的地方A到B和從B到C. 對不起不知道

0

在去仔細閱讀上面鏈接的文檔Google Map Parameters,我發現了這個問題第二部分的答案。

此外,我想知道如何我通過URL如果我需要說的地方A到B和從B到C.去

參數空間的部看起來通過將「+ to:」子句附加到查詢參數的daddr組件,允許按順序路由多個目標。

例如:

https://maps.google.com/maps?saddr=Ferry+Plaza+SF&daddr=Coit+Tower+to:Union+Square 

顯示了在輪渡廣場在舊金山,然後轉到科特塔,然後聯合廣場的順序開始的路線。

閱讀該維基的上述鏈接指示部分中有關'daddr ='參數的詳細信息。

通常,您可以通過參數檢查來確定Google地圖網址的外觀。如:

  • 訪問maps.google.com並與您感興趣的路線,目的地等的地圖查詢
  • 當你有一個地圖,你想是什麼樣子,請點擊鏈接圖標(看起來像一個鏈)來獲取與您指定的參數相對應的URL副本。
  • 將此URL粘貼到瀏覽器地址欄中。
  • 繼續解析出查詢字符串中的參數,以確定哪些部分與地圖上的內容對應。
  • 如果您不確定某個參數正在做什麼,請使用上面的mapki.com鏈接等頁面進行交叉引用。

你應該能夠推斷使用這個過程制定新的查詢。

+0

這兩個鏈接都死了,你能更新它們嗎? – j0k

1
NSString *ll = [NSString stringWithFormat:@"%f,%f", 
         self.placemark.location.coordinate.latitude, 
         self.placemark.location.coordinate.longitude]; 
    ll = [ll stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSString *url = [NSString stringWithFormat:@"http://maps.google.com/?q=%@", ll]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 

    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];