Google Maps Mapview不在标记上居中

时间:2018-06-29 17:24:47

标签: ios swift4 google-maps-sdk-ios

我正在使用Swift 4在ios中使用google maps,我必须在屏幕上显示一个带有标记的mapview,问题是,每当我显示mapview时,我都会得到以下结果:

enter image description here

我想要得到的结果是这样:

enter image description here

这是我使用的代码:

 func loadMap(location:CLLocation){
    self.mapView.isMyLocationEnabled = true
    self.mapView.isUserInteractionEnabled = true
    self.view.layoutIfNeeded()
    self.addLocationMarker()
}

func addLocationMarker(){
    // Creates a marker in the center of the map.
    let marker = GMSMarker()
    print(self.startLocation)
    marker.position = CLLocationCoordinate2D(latitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude)
    marker.map = self.mapView

    let camera = GMSCameraPosition.camera(withLatitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude, zoom: 12.0)
    self.mapView.camera = camera
}

地图视图是情节提要中视图的出口

1 个答案:

答案 0 :(得分:1)

此代码对我来说效果很好。试试看(快速4)

func setupMapView() {

    DispatchQueue.main.async {
      let position = CLLocationCoordinate2D(latitude: 32.9483364, longitude: -96.8241543)
      let marker = GMSMarker(position: position)
      self.mapView.camera = GMSCameraPosition(target: position, zoom: 15, bearing: 0, viewingAngle: 0)
      marker.title = "Enter marker title here"
      marker.map = self.mapView
    }  
}

注意:我已经使用了样本经度和纬度。您应该插入您的。