无法在iOS xcode项目

时间:2018-02-27 05:48:05

标签: ios swift xcode sdk maps

我正在尝试创建一个模拟应用程序,显示我学校的校园。我希望能够在校园中搜索,然后单击位置按钮以使屏幕跟随我的位置。查看下面的视频,了解我的问题。我的代码是专有的,因为我是swift和xcode的新手。我没有使用故事板,只是以编程方式创建这个应用程序。当我确实获得位置以不断更新我的位置并按照我的模拟位置时,它会撕下视图并重建它,这会导致它看起来非常小问题。此外,我不能通过改变在其他地方移动相机来打破更新。我确定我错过了很大的东西。为了尽可能地提高意识,我希望能够以平滑的外观跟踪屏幕上的位置,并停止更新位置,以便可以搜索校园而无需将屏幕更新到我当前的位置。 视频链接:[https://www.dropbox.com/s/op2kw9sfk0c8dm5/Xcode%20problem.mp4?dl=0][1]

这是我的代码:

    import UIKit
    import GoogleMaps
    import CoreLocation


    class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate{

    lazy var mapView = GMSMapView()
    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        GMSServices.provideAPIKey("AIzaSyBXEZf5gq-ewIjmlzyWlsDHJSsOTsHCm4k")

        let camera = GMSCameraPosition.camera(withLatitude: 35.046462, longitude: -85.298153, zoom: 15.8, bearing: 295, viewingAngle: 0)
        mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.mapType = .satellite
        //view = mapView

        //User Location
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
        locationManager.stopUpdatingLocation()
        view = mapView
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations[0]
        let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 15.8, bearing: 295, viewingAngle: 0)
        mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.mapType = .satellite
        mapView.isMyLocationEnabled = true
        mapView.settings.myLocationButton = true
        showMarker(position: CLLocationCoordinate2D.init(latitude: 35.046462, longitude: -85.298153), markerTitle: "Cardiac Hill", markerSnippet: "UTC")
        showMarker(position: CLLocationCoordinate2D.init(latitude: 35.047488, longitude: -85.300121), markerTitle: "Library", markerSnippet: "UTC")
        view = mapView         
    }

    func showMarker(position: CLLocationCoordinate2D, markerTitle: String, markerSnippet: String){
        let marker = GMSMarker()
        marker.position = position
        marker.title = "\(markerTitle)"
        marker.snippet = "\(markerSnippet)"
        marker.tracksViewChanges = true
        marker.opacity = 0.75
        marker.icon = GMSMarker.markerImage(with: .white)
        marker.map = mapView
    }

    func markerInfo(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
        var view = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 70))
        view.backgroundColor = UIColor.white
        view.layer.cornerRadius = 6

        let lbl1 = UILabel(frame: CGRect.init(x: 8, y: 8, width: view.frame.size.width - 16, height: 15))
        lbl1.text = "Cardiac label"
        view.addSubview(lbl1)

        let lbl2 = UILabel(frame: CGRect.init(x: lbl1.frame.origin.x, y: lbl1.frame.origin.y + lbl1.frame.origin.y + 3, width: view.frame.size.width - 16, height: 15))
        lbl1.text = "lbl2 info"
        view.addSubview(lbl2)

        return view
    }
}

感谢您的时间,我一定会每天检查一下,以回复所需的任何其他信息。 PS,我已经做了api和sdk导入,以及在info.plist中添加了信息。我似乎把所有事情都解决了,但是这个问题。

0 个答案:

没有答案