2016-11-24 5 views
0

Google지도 API를 사용하여 사용자에게 현재 위치를 표시하려고합니다. 몇 주 동안이 문제로 고심하고 코드가 실행되지만 시뮬레이터에서 위치를 변경할 때 현재 위치로 업데이트되지 않습니다.Google지도를 사용할 때 swift에서 myLocationEnabled가 myLocationEnabled로 변경됩니다.

내 코드가 다른 사람들이 수행하는 방법을 살펴본 후 모두 mapView.myLocationEnabled = true 인 반면 'myLocationEnabled'가 'isMylocationEnabled'로 이름이 변경되었다는 오류가 발생합니다. 나는 2 달 전부터 최신 게시물을 보았고 모든 사람들이 myLocationEnabled를 오류없이 사용하고 있는데, 왜 내가 이것을 얻고 있습니까? 내 현재 위치가 업데이트되지 않는 이유가 될 수 있습니까?

import UIKit 
import GoogleMaps 

class FirstViewController: UIViewController, CLLocationManagerDelegate { 


    @IBOutlet weak var mapView: GMSMapView! 


    let locationManager = CLLocationManager() 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     locationManager.delegate = self 
     mapView.settings.myLocationButton = true 
     mapView.settings.compassButton = true 
    } 
    override func viewDidAppear(_ animated: Bool) { 
     locationManager.requestWhenInUseAuthorization() 
    } 
    func locationManager(manager: CLLocationManager , didChangeAuthorizationStatus status: CLAuthorizationStatus) { 
     if status == .authorizedWhenInUse { 
      locationManager.startUpdatingLocation() 


      mapView.isMyLocationEnabled = true 

      mapView.settings.myLocationButton = true 
     } 
    } 
    func locationManager(manager: CLLocationManager ,didUpdateLocations locations: [CLLocation]) { 
     if let location = locations.first { 

      mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0) 

      let marker = GMSMarker() 
      marker.title = "Current Location" 
      marker.map = mapView 
      locationManager.stopUpdatingLocation() 
     } 
    } 
} 
+0

는 u는 구글 개발자 콘솔에서 프로젝트를 생성 했 작동하도록이 코드를 사용? 그리고 그건 그렇고 당신이 중 하나를 통해 UR 오래된 게시물을 http://stackoverflow.com/questions/40318101/current-location-update-on-google-maps-sdk-for-xcode-not-working 업데이 트하거나 삭제하는 대신 삭제해야합니다 같은 문제가있는 새로운 것. 이 https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial도 도움이 될 수 있습니다. – LoVo

+0

안녕하세요, 맞습니다. 내 대리인에 내 API 키가 있고 Google지도가 표시되지만 현재 위치는 표시되지 않습니다. 죄송합니다. 이전 게시물을 삭제하겠습니다. 그것은 실제로 내가 처음에 따라 왔던 튜토리얼 이었지만 동일한 문제를 겪고있는 그의 흔적은 없습니다. 나는 또한이 튜토리얼 https://www.appcoda.com/google-maps-api-tutorial/ 및 온라인에서 찾은 다른 사람들도 시도했다. 그런데 'isMyLocationEnabled'는 BOOL입니다. 문제가 될 수 있습니까? Frameworks에 문제가 될 수 있습니까? GoogleMaps SDK를 수동으로 다운로드했기 때문에 무언가를 놓친 적이 있으십니까? –

답변

0

그럼 내가 최종적으로! 기본적으로 기존 Podfile을 GoogleMaps 및 GooglePlaces로 업데이트 한 다음 모든 프레임 워크가 작동하도록 Pod를 업데이트했습니다. 그럼 난 내 현재 위치

import UIKit 

    import GoogleMaps 


    class FirstViewController: UIViewController, CLLocationManagerDelegate { 


@IBOutlet weak var mapView: GMSMapView! 
var locationManager = CLLocationManager() 
var vwGMap = GMSMapView() 


override func viewDidLoad() { 
    super.viewDidLoad() 
    let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 22.300000, longitude: 70.783300, zoom: 10.0) 
    vwGMap = GMSMapView.map(withFrame: self.view.frame, camera: camera) 
    vwGMap.camera = camera 

    locationManager.delegate = self 
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer 
    locationManager.distanceFilter = 500 
    locationManager.requestWhenInUseAuthorization() 
    locationManager.requestAlwaysAuthorization() 
    locationManager.startUpdatingLocation() 

    self.view = vwGMap 
    } 

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { 

     if (status == CLAuthorizationStatus.authorizedWhenInUse) 

     { 
      vwGMap.isMyLocationEnabled = true 
     } 
    } 
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     let newLocation = locations.last 
     vwGMap.camera = GMSCameraPosition.camera(withTarget: newLocation!.coordinate, zoom: 15.0) 
     vwGMap.settings.myLocationButton = true 
     self.view = self.vwGMap 
    let marker = GMSMarker() 
    marker.position = CLLocationCoordinate2DMake(newLocation!.coordinate.latitude, newLocation!.coordinate.longitude) 
    marker.map = self.vwGMap 
    } 

}