谷歌地图选择适用于iOS的地方选择器 - 在Swift中出现GMSPlacePicker但在动画结束时消失

bri*_*ear 1 google-maps ios google-maps-sdk-ios swift

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

但是Picker出现但是一旦从Right到Left的转换完成就会立即消失.

    //  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")
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序已成功要求位置

我有一个谷歌地图的桥接标题.

我没有使用可可豆荚来安装框架

但我以前在Obj-C中使用过这个框架

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

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

在此输入图像描述

当我运行它时,我可以在采摘地图中看到悉尼.

它从屏幕的右侧过渡到左侧.

当它到达左边时它会消失

我添加了Reveal应用程序,我无法看到离线器的选择器视图.

我的GMS服务api密钥是正确的,因为我在obj-c app中用来显示Places Picker.

Bundle id是正确的.

我的快速知识是"我想我知道.我可能不知道"

有任何想法吗?

小智 8

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