Trying to add a marker to Google map,but the app is getting crashed at while addMarker()
function call,Exception details are as follows,
Terminating app due to uncaught exception 'GMSThreadException', reason: 'All calls to the Google Maps SDK for iOS must be made from the UI thread'
FYI vwGogleMap is global and in a function I'm trying to plot marker.
func addMarker() -> Void
{
var vwGogleMap : GMSMapView?
var position = CLLocationCoordinate2DMake(17.411647,78.435637)
var marker = GMSMarker(position: position)
marker.title = "Hello World"
marker.map = vwGogleMap
}
Any help would be appreciated,
TIA.
/// Marker - Google Place marker
let marker: GMSMarker = GMSMarker() // Allocating Marker
marker.title = "Title" // Setting title
marker.snippet = "Sub title" // Setting sub title
marker.icon = UIImage(named: "") // Marker icon
marker.appearAnimation = .pop // Appearing animation. default
marker.position = location.coordinate // CLLocationCoordinate2D
DispatchQueue.main.async { // Setting marker on mapview in main thread.
marker.map = mapView // Setting marker on Mapview
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With