How to show custom images on google maps using swift

淺唱寂寞╮ 提交于 2019-12-08 02:41:43

问题


How can I show these kind of car images in picture on google maps according to latitude & longitude?

I tried the following code, but I got the following incorrect result

 let marker1 = GMSMarker()
        let marker2 = GMSMarker()
        let marker3 = GMSMarker()
        let marker4 = GMSMarker()
        let marker5 = GMSMarker()
        let markerImage = UIImage(named: "white_car_icon copy.png")!.withRenderingMode(.alwaysTemplate)

        let markerView = UIImageView(image: markerImage)
        marker1.position = CLLocationCoordinate2D(latitude: 12.9077923, longitude: 77.586962)
        marker2.position = CLLocationCoordinate2D(latitude: 12.9077923, longitude: 77.586962)
        marker3.position = CLLocationCoordinate2D(latitude: 12.9077856, longitude: 77.58695950000001)
        marker4.position = CLLocationCoordinate2D(latitude: 12.90782858, longitude: 77.58678956)
        marker5.position = CLLocationCoordinate2D(latitude: 12.90780888511306, longitude: 77.58487723767757)
        marker1.iconView = markerView
        marker1.map = mapView
        marker2.iconView = markerView
        marker2.map = mapView
        marker3.iconView = markerView
        marker3.map = mapView
        marker4.iconView = markerView
        marker4.map = mapView
        marker5.iconView = markerView
        marker5.map = mapView

If anyone could help me with this, I'd be thankful to you. I have been trying it for the past 4 days, but didn't get correct output.


回答1:


The right option is using the icon property

 marker5.icon = UIImage(named: "paradero")

With this you can set any image you want.



来源:https://stackoverflow.com/questions/44726012/how-to-show-custom-images-on-google-maps-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!