如何使用swift在谷歌地图上显示自定义图像 [英] How to show custom images on google maps using swift

查看:186
本文介绍了如何使用swift在谷歌地图上显示自定义图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Google地图上显示这类汽车图片 b $ b根据纬度&经度?

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

我尝试了以下代码,但我得到了以下错误结果

 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

如果有人能帮助我,我会很感激你。我一直在尝试它过去4天,但没有得到正确的输出。

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.

推荐答案

正确的选项是使用icon property

The right option is using the icon property

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

使用此功能,您可以设置任何想要的图片。

With this you can set any image you want.

这篇关于如何使用swift在谷歌地图上显示自定义图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆