UIWebview中的Google地图直接显示行车路线而非地图

Kam*_*ani 4 iphone ipad

我加载在UIWebView的谷歌地图提供的经纬度长坐标源和destination.But的问题是,它显示行车路线时,得到loaded.If我们想看到的地图,然后我们要在地图上点击按钮提供在地址旁边.我需要在加载Web视图时直接显示地图而不是行车路线.任何人都可以告诉我如何实现这一目标.

 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 *urlString=@"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];
Run Code Online (Sandbox Code Playgroud)

另外我想知道如果我需要从说到位置A到B和从B到C,我如何传递URL.

Sur*_*rma 9

只需更改您的网址行即可

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];
Run Code Online (Sandbox Code Playgroud)

使用以下代码

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];
Run Code Online (Sandbox Code Playgroud)

唯一添加的是output=embed强制网络直接打开地图而不打开屏幕,要求填充输入框的源和目的地.

有关更多说明,您还可以查看谷歌地图参数中谷歌地图中使用的所有参数

以上将解决您的第一个查询.

关于第二个查询,即如果我需要从说到位置A到B,从B到C,我想知道如何传递URL. 抱歉不知道