2016-12-02 4 views

답변

11

GMSMarker.markerImage(with: <UIColor?>)을 사용하여 마커 아이콘을 재설정 할 수 있습니다.

문서 : Google Maps iOS SDK GMSMarker Class Reference

import GoogleMaps 

// view controller 
class MapViewController: UIViewController { 

    // outlets 
    @IBOutlet weak var mapView: GMSMapView! 

    // view did load method 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     // set map view delegate 
     mapView.delegate = self 
    } 
} 

// extension for GMSMapViewDelegate 
extension MapViewController: GMSMapViewDelegate { 

    // tap map marker 
    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { 
     print("didTap marker \(marker.title)") 

     // remove color from currently selected marker 
     if let selectedMarker = mapView.selectedMarker { 
      selectedMarker.icon = GMSMarker.markerImage(with: nil) 
     } 

     // select new marker and make green 
     mapView.selectedMarker = marker 
     marker.icon = GMSMarker.markerImage(with: UIColor.green) 

     // tap event handled by delegate 
     return true 
    } 
}