Это то, что я сделал до сих пор. Когда я вызываю функции «Применить изображение», у всех видимых маркеров установлены свои изображения, но возникают проблемы, когда я уменьшаю карты и проверяю другие маркеры, их изображения продолжают мерцать и не прекращаются. Также я хочу, чтобы мои изображения были круглыми, но они продолжают превращаться в шестиугольник. Вот изображение, показывающее проблему.
func showCurrentLocationWithOnlineMarkers() {
guard let locationObj = locationManager.location else {
return
}
viwMaps.delegate = self
let coord = locationObj.coordinate
userLat = coord.latitude
userLng = coord.longitude
let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: userLat, longitude: userLng, zoom: Float(17.0))
viwMaps.isMyLocationEnabled = true
viwMaps.settings.myLocationButton = true
self.viwMaps.animate(to: camera)
for data in arrGetDriverModal{
let driver_lat = CLLocationDegrees(data.driver_lat ?? "")
let driver_long = CLLocationDegrees(data.driver_long ?? "")
let location = CLLocationCoordinate2D(latitude: driver_lat!, longitude: driver_long!)
let marker = GMSMarker()
marker.position = location
marker.userData = data
marker.map = self.viwMaps
let imageURL = URL(string: API.imgbaseURL+data.driver_image!)
self.applyImage(from: imageURL!, to: marker)
}
}
func applyImage(from url: URL, to marker: GMSMarker) {
let imageView = UIImageView(image: #imageLiteral(resourceName: "marker"))
imageView.frame = CGRect.init(x: 0, y: 0, width: 44, height: 44)
DispatchQueue.global(qos: .background).async {
guard let data = try? Data(contentsOf: url),
let image = UIImage(data: data)
else { return }
DispatchQueue.main.async {
imageView.image = image
imageView.layer.cornerRadius = 22
imageView.clipsToBounds = true
imageView.layer.masksToBounds = true
marker.iconView = imageView
}
}
}