Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to add GMS Mapview from the google maps api into my app. When I followed a tutorial for how to implement it, Xcode cant seem to understand that GMSMapview is an UIView.

This is my code

import SwiftUI
import GoogleMaps

struct MapsView: UIViewRepresentable {

private let zoomLevel: Float = 10.0
@ObservedObject var locationManager = LocationService()

func makeUIView(context: Context) -> some GMSMapView {
    let camera = GMSCameraPosition.camera(withLatitude: locationManager.lat, longitude: locationManager.lat, zoom: zoomLevel)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    return mapView
}

func updateUIView(_ mapView: GMSMapView, context: Context) {
    mapView.animate(toLocation: CLLocationCoordinate2D(latitude: locationManager.lat, longitude: locationManager.lon))
}

}

Xcode does not show any type of solutions for me to make it conform either.

In my Podfile I have only added "GoogleMaps" without version num. So I believe I am using the newest version.

Is this a known bug in the Google Maps package or am I doing something wrong?

question from:https://stackoverflow.com/questions/65644002/swiftui-gmsmapview-does-not-conform-to-protocol-uiviewrepresentable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
621 views
Welcome To Ask or Share your Answers For Others

1 Answer

Remove some word.

func makeUIView(context: Context) -> GMSMapView { //<-- here
    let camera = GMSCameraPosition.camera(withLatitude: locationManager.lat, longitude: locationManager.lat, zoom: zoomLevel)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    return mapView
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...