2016-04-04 19 views
1

Ben ilk görünüm harita üzerinde kullanıcının geçerli pozisyonu elde etmeye çalışıyorum ama her zaman hat 22 üzerinde uygulama ölürüm. Bana ya da belki başka bir şekilde bunu yardımcı olabilir herkese çok teşekkür ederim aşağıdaki kodu içinGoogleMaps IOS SDK: viewMap.myLocationEnabled = true. çalışma değil

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") 
    } 


} 

cevap

0

Bu hizmeti kullanmak için görüş sınıf türünü ayarlamak gerekir

viewMap.myLocationEnabled = true 

bu hatayı Atar Arayüz Oluşturucudaki GMSMapView (görünümünüzü Özel Denetçiye Kimlik Denetçisine ayarlayın). Şu anda UIView, ve mesaj setMyLocationEnabled mesajını gönderiyorsunuz: tanınmayan.

+0

Evime dönüyorum ve deneyeceğim. Çok teşekkürler – user3324336

+0

Bu çalışır! : D thx – user3324336

+0

Yardım ettiğim için sevindim! Cevapları kabul edildi olarak işaretleyebilir misiniz? Teşekkürler! – stakri