2016-04-04 14 views
1

私は最初のビューを取得しようとしているが、マップ上のユーザーの現在の位置ですが、私は常に22行目のアプリケーションを終了します。これを行うには、GoogleMaps IOS SDK:viewMap.myLocationEnabled = true。役に立たなかった

viewMap.myLocationEnabled = true 

は、このエラーを例外:次のコードのための

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setMyLocationEnabled:]: unrecognized selector sent to instance 0x14c5bde10' 

import UIKit 
import GoogleMaps 

class WhereViewController: UIViewController, CLLocationManagerDelegate { 


    @IBOutlet weak var viewMap: GMSMapView! 
    var locationManager = CLLocationManager() 
    var didFindMyLocation = false 



    override func viewDidLoad() { 
     super.viewDidLoad() 

     locationManager.delegate = self 
     locationManager.requestWhenInUseAuthorization() 

     viewMap.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil) 
     print("despues de observer") 
     viewMap.myLocationEnabled = true // Line 22 
    } 

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { 
     if status == CLAuthorizationStatus.AuthorizedWhenInUse{ 
      viewMap.myLocationEnabled = true 
      print("sali de locationManager") 
     } 
    } 

    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { 
     if !didFindMyLocation{ 
      print("dentro de observer false") 
      let myLocation: CLLocation = change![NSKeyValueChangeNewKey] as! CLLocation 
      viewMap.camera = GMSCameraPosition.cameraWithTarget(myLocation.coordinate, zoom: 10.0) 
      viewMap.settings.myLocationButton = true 

      didFindMyLocation = true 
     } 
     print("dentro de observer false") 
    } 


} 

答えて

0

あなたがあなたの視野のクラスタイプを設定する必要がありますInterface BuilderのGMSMapView(アイデンティティインスペクタでビューのカスタムクラスを設定)現在はUIViewであり、認識できないメッセージsetMyLocationEnabled:を送信しています。

+0

私は私の家に戻り、私は試してみる。ありがとうございます – user3324336

+0

これは動作します! :D thx – user3324336

+0

助けてくれてうれしい!あなたは答えを受け入れたものとしてマークしてください。どうも! – stakri

関連する問題