Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GoogleMaps将iOS-GMSPlacePicker放置在Swift中,但在动画结束时消失_Ios_Swift_Google Maps_Google Maps Sdk Ios - Fatal编程技术网

GoogleMaps将iOS-GMSPlacePicker放置在Swift中,但在动画结束时消失

GoogleMaps将iOS-GMSPlacePicker放置在Swift中,但在动画结束时消失,ios,swift,google-maps,google-maps-sdk-ios,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: Any

我正在尝试将简单的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")
            }
        }
    }
}
我的应用程序已成功请求位置

我有一个到谷歌地图的桥接头

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

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

所以只需将GoogleMaps.framework拖到project 以及内部资源包

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

当我运行它时,我可以在pickers地图上看到悉尼

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

当它到达左边时就消失了

我添加了“显示”应用程序,无法脱机查看选择器视图

我的GMS服务api密钥与我在obj-c应用程序中用于显示位置选择器的密钥一样正确

包id是正确的

我的快速知识是“我想我知道,我可能不知道”


有什么想法吗?

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

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

修复了将其设置为ivar…DOH

class ViewController: UIViewController {
    var placePicker : GMSPlacePicker?

    @IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {

        self.placePicker?.pickPlaceWithCallback(){

        ...

修好了,把它变成了一个ivar…啊

class ViewController: UIViewController {
    var placePicker : GMSPlacePicker?

    @IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {

        self.placePicker?.pickPlaceWithCallback(){

        ...

你应该向上面的菲林给出答案,因为他是为你提供答案的人。你应该向上面的菲林给出答案,因为他是为你提供答案的人。