如何在Google地图中制作圆形标记?

时间:2019-05-15 19:22:30

标签: ios swift xcode

我将UIImage(照片用户)应用于Google Map中的标记,但结果却是正方形,如何使其变为圆形,如屏幕截图所示? enter image description here enter image description here     导入UIKit     导入GoogleMaps

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Create a GMSCameraPosition that tells the map to display the
        // coordinate -33.86,151.20 at zoom level 6.
        let camera = GMSCameraPosition.camera(withLatitude: 48.4811403, longitude: 35.0687614, zoom: 15.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        view = mapView

        // Creates a marker in the center of the map.
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 48.4811403, longitude: 35.0687614)
        marker.title = "Alexei"
        marker.snippet = "From here"
        marker.map = mapView
        marker.icon = Person.shared.personImage
        marker.icon = self.imageWithImage(image: Person.shared.personImage!, scaledToSize: CGSize(width: 35.0, height: 35.0))

    }

    func imageWithImage(image:UIImage, scaledToSize newSize:CGSize) -> UIImage{
        UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
        image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
        let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
        return newImage
    }
}

0 个答案:

没有答案