ios - Google maps Places Picker for iOS - Swift 中的 GMSPlace Picker 出现但在动画结束时消失

标签 ios swift google-maps google-maps-sdk-ios

我正在尝试将简单的 GMSPlacePicker 示例转换为 Swift

但是选择器会出现,但一旦从右到左的过渡完成,它就会立即消失。

    //  ViewController.swift
import UIKit
import CoreLocation
import GoogleMaps

class ViewController: UIViewController {

    @IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {

        //-----------------------------------------------------------------------------------
        var southWestSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8659, 151.1953)
        var northEastSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8645, 151.1969)

        var sydneyBounds : GMSCoordinateBounds = GMSCoordinateBounds(coordinate: southWestSydney, coordinate:northEastSydney)

        //var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:sydneyBounds)
        var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:nil)

        //---------------------------------------------------------------------
        var placePicker : GMSPlacePicker = GMSPlacePicker(config: config)

        //typealias GMSPlaceResultCallback = (GMSPlace?, NSError?) -> Void

        var error: NSError? = nil
        var gmsPlace: GMSPlace? = nil

        placePicker.pickPlaceWithCallback(){
            (gmsPlace, error) -> Void in
            if let error = error{
                println("error:\(error)")
            }else{
                if let gmsPlace = gmsPlace{
                    if let formattedAddress = gmsPlace.formattedAddress{
                        println("formattedAddress:\r\(formattedAddress)")
                    }else{
                        println("gmsPlace.formattedAddress is nil")
                    }

                }else{
                    println("gmsPlace is nil")
                }

                println("info")
            }
        }
    }
}

我的应用已成功请求位置信息

我有一个连接到 Google map 的标题。

我没有使用cocoa pods来安装框架

但是我之前用过Obj-C的框架

所以只需将 GoogleMaps.framework 拖到项目中 和内部资源包

我添加了之前教程中的所有以下内容和链接器错误:

enter image description here

当我运行它时,我可以在采摘者 map 中看到悉尼。

它从屏幕右侧过渡到左侧。

当它到达左边时它就消失了

我添加了 Reveal 应用程序,但无法离线查看选择器 View 。

我的 GMS 服务 api key 是正确的,因为它是我在 obj-c 应用程序中用来显示 Places Picker 的 key 。

Bundle id 是正确的。

我的 Swift 知识是“我想我知道。我可能不知道”

有什么想法吗?

最佳答案

您应该保留对 GMSPlacePicker 的引用。使其成为属性而不是局部变量。

关于ios - Google maps Places Picker for iOS - Swift 中的 GMSPlace Picker 出现但在动画结束时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122239/

相关文章:

swift - Google 通过 Firebase 登录 : GIDSignInDelegate does not conform to ViewController

swift - 如何正确处理多个 if else 条件?

javascript - 如何动态设置谷歌地图样式

ios - HighQualityFormat 的 PHImageManager.requestImageForAsset 从不调用 resultHandler

iOS stringByEvaluatingJavaScriptFromString - UI 卡住

Swift Quick/Nimble 测试未运行

android - Maps v3.0.0 Beta 的 Proguard 规则

javascript - 将数组中的值分配给键

ios - 将自定义节标题 View 的左对齐与其他标准标题和单元格相匹配

iOS AES256解密