iOS Development

ios – GMSMapView strikes digital camera to top-left as a substitute of heart

Spread the love

I need to use a Google map in a swiftUI mission and for that objective, I created a UIViewControllerRepresentable struct, the map is working nicely within the simulator, and CLLocationCoordinate2D is about to the middle of the map, however after I run it on an actual system the google map put the situation within the top-left nook as a substitute of the middle,
how can I put the situation precisely within the heart of the map display screen?

struct MapView: UIViewControllerRepresentable {
    @Binding var markers: [GMSMarker]
    @Binding var selectedMarker: GMSMarker?
    @Binding var selectedLocation: MapRegionAreaLocationModel
    var defaultZoomLevel: Float = 10
    let isUserInteractionEnabled: Bool
    var onAnimationEnded: () -> ()
    //var mapViewWillMove: (Bool) -> ()
    func makeUIViewController(context: Context) -> MapViewController {
        let uiViewController = MapViewController() = context.coordinator
        return uiViewController
    personal func setStyleToMap(_ uiViewController: MapViewController) {
        do {
            if let styleURL = Bundle.foremost.url(forResource: "type", withExtension: "json") {
       = attempt GMSMapStyle(contentsOfFileURL: styleURL)
            } else {
                //     DDLogWarn("Unable to search out type.json")
        } catch {
            //DDLogWarn("A number of of the map kinds didn't load. (error)")
    func updateUIViewController(_ uiViewController: MapViewController, context: Context) {
        guard let newLatitude = selectedLocation.latitude, let newLongitude = selectedLocation.longitude else {
        let coordinate = CLLocationCoordinate2D(latitude: newLatitude, longitude: newLongitude)
        let digital camera = camera(withTarget: coordinate, zoom: Float(selectedLocation.depth ?? 12)) /*GMSCameraUpdate.setCamera(*/ digital camera)
        markers.forEach { marker in
        if let selectedMarker = selectedMarker {
            let digital camera = camera(withTarget:, zoom: defaultZoomLevel)
            print("Animating to place (")
            CATransaction.setValue(NSNumber(floatLiteral: 1), forKey: kCATransactionAnimationDuration)
   GMSCameraUpdate.setCamera(digital camera))
            CATransaction.commit() }
    func makeCoordinator() -> MapViewCoordinator {
        return MapViewCoordinator(self)
    ultimate class MapViewCoordinator: NSObject, GMSMapViewDelegate {
        var mapView: MapView
        init(_ mapView: MapView) {
            self.mapView = mapView
        func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
        func mapView(_ mapView: GMSMapView, idleAt place: GMSCameraPosition) {

Leave a Reply

Your email address will not be published. Required fields are marked *