如何在UIWebView中打开Goog​​le街景?

时间:2011-08-02 14:43:42

标签: iphone ios4 iphone-sdk-3.0

我试图在UIWebView中打开街景但它不起作用。我只能看到普通的地图。我该如何解决?还有其他可能性吗?

这是我的代码:

NSString *urlAddress = @"http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[webV loadRequest:requestObj];

3 个答案:

答案 0 :(得分:2)

尝试为您的UIWebview加载此代码:

NSString *latLongString =[NSString stringWithFormat:@"%f,%f", latitude, longitude];

[_uiWebView loadHTMLString:[NSString stringWithFormat:@"<html><head><meta name='viewport',user-scalable=no'/><script src='http://maps.google.com/maps/api/js?sensor=false'type='text/javascript'></script></head><body onload=\"new google.maps.StreetViewPanorama(document.getElementById('p'),{position:new google.maps.LatLng(%@)});\" style='padding:0px;margin:0px;'><div id='p' style='height:100%%; width:100%%;'></div></body></html>",latLongString] baseURL:nil];

答案 1 :(得分:1)

只需在您的webView中运行Google地图网址请求,然后在webViewDidFinishLoad方法中添加以下行以隐藏提醒。 webView.stringByEvaluatingJavaScriptFromString( “document.getElementsByClassName( '毫升-不受支持 - 连接 - 对话框的容器')[0] = .style.display '无'”)

以下是在UIWebView中加载Google StreetView的示例调用。我用过Swift。

let urlAddress = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";            
        
        let request = NSURLRequest(URL: NSURL(string: urlAddress)!)
        glWebView.loadRequest(request)

答案 2 :(得分:0)

没有。你无法做到这一点。

见这里 但你可以喜欢这个

http://maps.google.com/?q=Tokyo@35.680,139.769

您可以将此链接传递给您的webview以加载它。

见这里

Does MapKit allow for StreetView?