Swift 2 GMSPanoramaCallback来确定Google街景是否可用 [英] Swift 2 GMSPanoramaCallback to determine if Google Street View is available

查看:136
本文介绍了Swift 2 GMSPanoramaCallback来确定Google街景是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用方法



panoViewService.requestPanoramaNearCoordinate(坐标:CLLocationCoordinate2D:CLLocationCoordinate2D,回调:GMSPanoramaCallback)

其中panoViewService = GMSPanoramaService()



检查某个特定坐标是否存在Google街景视图。我不清楚回调函数返回的内容,以及如何使用它来加载街景视图(如果存在)或者如果不存在,则加载替代视图。我知道已经发布了类似的问题,但是没有一个是针对Swift 2的,我不知道如何修改Swift的Obj-C代码。 解决方案

好的,我明白了。

  var panoViewService = GMSPanoramaService()

覆盖func viewDidLoad( ){
super.viewDidLoad()
let coord = place.position //从前一个ViewController加载的数据

panoViewService.requestPanoramaNearCoordinate(coord,radius:100){
GMSPanorama:GMSPanorama ?, NSError:NSError?)in

如果GMSPanorama!= nil {//也可以使用NSError == nil
//代码在这里加载我的全景视图
} else {
//在这里做别的事
}
}

}

I am trying to use the method

panoViewService.requestPanoramaNearCoordinate(coordinate: CLLocationCoordinate2D: CLLocationCoordinate2D, callback: GMSPanoramaCallback)

where panoViewService = GMSPanoramaService()

to check if a Google Street View is present for a particular coordinate. I am unclear on what is returned by the callback and how I can use it to load the street view if it is present or to load an alternative view if not. I know there are similar questions already posted, but none are for Swift 2 and I don't know how to adapt the Obj-C code for Swift.

解决方案

Ok, I figured it out. The following code does what I need.

var panoViewService = GMSPanoramaService()

override func viewDidLoad() {
     super.viewDidLoad()
     let coord = place.position // data loaded from previous ViewController

     panoViewService.requestPanoramaNearCoordinate(coord, radius: 100) {
          GMSPanorama: GMSPanorama?, NSError: NSError?) in

         if GMSPanorama != nil {  // could have also used if NSError == nil
              // code to load my panorama view here
         } else {
             // do something else here
         }
     }

}

这篇关于Swift 2 GMSPanoramaCallback来确定Google街景是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆