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

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

本文介绍了UIWebview中的Google地图直接显示行车路线而非地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIWebview中加载谷歌地图,为源和目的地提供lat长坐标。但问题是它显示了加载时的行车路线。如果我们想要查看地图,那么我们必须点击在地图旁边提供的地图按钮。我需要在加载网页视图时直接显示地图而不是行车路线。
任何人都可以告诉我如何实现这一点。

I am loading google maps in UIWebview by providing the lat long co-ordinates for the Source and destination.But the problem is it shows the driving directions when it gets loaded.If we want to see the map then we have to click on the map button provided alongside the address.I need to directly show the map instead of driving directions when the web view gets loaded.Can any one tell me how do I achieve this.

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

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

Also I would like to know how to I pass the url if i need to go from say place A to B and from B to C.

推荐答案

只需更改您的网址

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 这会强制网络直接打开地图而不打开屏幕,该屏幕要求填写输入框以显示源和目的地。

The only thing added is output=embed which forces the web to open the map directly without opening the screen which asks for filled input box for source and destination.

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

For more clarifications you can also check out all the parameters that are used in google map from Google Map Parameters

以上将解决你的第一个查询。

Above will solve your first query.

关于第二个查询
ie我也想知道如果我需要从说到的地方A到B和B到C.
抱歉不知道

这篇关于UIWebview中的Google地图直接显示行车路线而非地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:25