我正在尝试使用GMSMarker
更改Moa
图标,但标记仍显示默认图标。这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
locationmanager.delegate = self
let authorizationStatus = CLLocationManager.authorizationStatus()
if(authorizationStatus == .authorizedWhenInUse || authorizationStatus == .authorizedAlways) {
locationmanager.startUpdatingLocation()
MapView.isMyLocationEnabled = true
MapView.settings.myLocationButton = true
} else {
locationmanager.requestWhenInUseAuthorization()
}
MapView.camera = GMSCameraPosition.camera(withLatitude: 32.4279, longitude: 53.6880, zoom: 5)
MapView.delegate = self
prepareMapMarkers()
}
func prepareMapMarkers(){
let marker = GMSMarker(position: CLLocationCoordinate2D(latitude: CLLocationDegrees(malls[0].lat), longitude: CLLocationDegrees(malls[0].long)))
marker.map = MapView
moa.onSuccess = { image in
print(image)
marker.icon = image.images?[0]
return image
}
moa.url = "http://www.w3schools.com/css/img_fjords.jpg"
}
控制台
<UIImage: 0x60000009e050>, {600, 400}
该图片仅供测试。为什么它不起作用?
答案 0 :(得分:3)
试试这个!它对我有用
let pin = UIImage(named: "maps_icon_location")!.imageWithRenderingMode(.AlwaysTemplate)
marker.icon = pin
答案 1 :(得分:0)
您尝试在添加标记后更改标记的图像。我不确定Google Maps SDK是否支持此功能,但这不是一个好主意。而是下载你的照片,然后创建标记并将其添加到地图:
moa.onSuccess = { image in
let marker = GMSMarker(position: CLLocationCoordinate2D(latitude: CLLocationDegrees(malls[0].lat), longitude: CLLocationDegrees(malls[0].long)))
marker.icon = image.images?[0]
marker.map = self.MapView
}
moa.url = "http://www.w3schools.com/css/img_fjords.jpg"