开发者

How to load google street view in a UIWebView of iphone app?

开发者 https://www.devze.com 2023-02-05 11:45 出处:网络
I am trying to use the google map street view in my app, so i am trying to load the html file in my Webview. but it is need the flash player to show the street view.

I am trying to use the google map street view in my app, so i am trying to load the html file in my Webview. but it is need the flash player to show the street view.

Is adobe flash player is required for this?

Anyone know how to use the street view in our ip开发者_如何学编程hone app?

Regards,


Yes, it is possible to load Google StreetView in UIWebView. Here is a sample code example to load Google StreetView -

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)

After loading this streetView. Google will give you an alert that this URL is belongs to google map only. To hide that alert message just add this below javascript query in your WebViewDidFinish method -

webView.stringByEvaluatingJavaScriptFromString("document.getElementsByClassName('ml-unsupported-link-dialog-container')[0].style.display='none'")


Well technically it is not possible, but if you can get the panorama image id for that specific latitude and longitude, then it is possible. In my previous answer, I said it is possible as because I know the panorama id for that specific location. Using that code you can open steetview in your UIWebview, but it will show a warning. By touching anywhere in your webview will disappear that warning alert.

Bu Google introduce there SDK to load streetview in your iOS app, instead of leaving your app. All you need to do is add 'GoogleMaps' sdk using cocoa pods and run this below source code to display google Streetview for specific latitude and longitude.

let panoSvc = GMSPanoramaService()
            panoSvc.requestPanoramaNearCoordinate(CLLocationCoordinate2D(latitude: 32.847683, longitude: -96.771638), radius:100, callback: { (panorama, error) in
                if error == nil {
                    DispatchQueue.main.async(execute: {
                        let panoView = GMSPanoramaView(frame: .zero)
                        self.view = panoView
                        panoView.moveNearCoordinate((panorama?.coordinate)!, radius: 200)
                        print("Panorama ID: ", panorama?.panoramaID)
                        print("Panorama Co-ordinate: ", panorama?.coordinate)
                    })
                }
                else {
                    Utility.showCustomMsg(self.view, label: "Not Found", detailslbl:"Street View is not available for this location.", isSuccessImg: false, duration: 3)
                    {
                        self.navigationController?.popViewController(animated: true)
                    }
                }
            })

Cool huh...... Thanks goes to Google for their cool staff.

0

精彩评论

暂无评论...
验证码 换一张
取 消