更改 google 映射 Poitum 标记
Changing google maps POIItem markers
我正在构建一个 iOS 应用程序,我想在其中更改默认的红色 google 地图标记,不幸的是,我试图在整个互联网上查找,但找不到任何解决方案。
我的问题是我已经使用 gmaps utils 实现了 gmaps 集群,但我似乎无法找到更改 class POIItem 项目图标的方法。当尝试更改制造商外观时,会显示默认和自定义的两个标记。
所以这是一个代码片段:
func getClubs(){
ref.child("Clubs").observe(.value, with: { (snapshot) in
for child in snapshot.children{
let snap = child as! DataSnapshot
let value = snap.value as? [String: Any]
//print(value!)
let name = value?["Name"] as? String
//let latitude = value?["Latitude"] as? String
//let longitude = value?["Longitude"] as? String
let contact = value?["Contact"] as? String
let prix = value?["Prix"] as? [String:Int]
var adresse = value?["Adresse"] as? String
if adresse == nil {
adresse = value?["Address"] as? String
}
var idFB = value?["ID Facebook"] as? Int
if idFB == nil {
idFB = value?["Facebook ID"] as? Int
}
//let clubFbId = String(describing: idFB)
//print(clubFbId)
print("\(idFB)")
let clubStruct: Club = Club(name: name!, adresse: adresse!, contact: contact!, clubIdFb: idFB!)
if prix != nil {
clubStruct.prix = prix
}
self.clubArray.updateValue(clubStruct, forKey: idFB!)
print(self.clubArray[idFB!]?.name)
}
}){ (error) in
print(error.localizedDescription)
}
ref.child("Events").observe(.value, with: { (snapshot) in
//var indice: Int = 1
for child in snapshot.children{
let snap = child as! DataSnapshot
//print(snap.key)
let event = snap.childSnapshot(forPath: "0").value as? [String:Any]
let place = snap.childSnapshot(forPath: "0").childSnapshot(forPath: "place").value as? [String:Any]
let clubFbId = place?["id"] as? String
let name = event?["name"] as? String
let start_time = event?["start_time"] as? String
let end_time = event?["end_time"] as? String
let eventFbId = event?["id"] as? String
let videoURL = event?["videoURL"] as? String
let timetable = event?["timetable"] as? [String:String]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.timeZone = TimeZone(abbreviation: "GMT+2:00")
let start = dateFormatter.date(from: start_time!)!
let end = dateFormatter.date(from: end_time!)!
if self.currentDate! > end {
continue
}
let location = snap.childSnapshot(forPath: "0").childSnapshot(forPath: "place").childSnapshot(forPath: "location").value as? [String:Any]
let latitude = location?["latitude"] as? CLLocationDegrees
let longitude = location?["longitude"] as? CLLocationDegrees
let eventStruct: Event = Event(latitude: latitude!, longitude: longitude!, clubIdFb: clubFbId!, eventIdFb: Int(eventFbId!)!, name: name!, start: start, end: end, idFirebase: snap.key)
if videoURL != nil {
eventStruct.videoURL = videoURL
}
if timetable != nil {
eventStruct.timetable = timetable
}
self.eventArray.updateValue(eventStruct, forKey: clubFbId!)
//print(self.eventArray[clubFbId!]?.name)
let event_marker = GMSMarker()
let clubimage = UIImage(named: "clubmarker")
let markerView = UIImageView(image: clubimage)
markerView.frame = CGRect(x: 0, y: 0, width: 58, height: 103)
event_marker.position = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
event_marker.map = mapViewFirst
event_marker.iconView = markerView
event_marker.isTappable = true
event_marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
let position = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
let event_item = POIItem(position:position, marker: event_marker)
self.clusterManager.add(event_item)
self.clusterManager.cluster()
// var iconGenerator : GMUDefaultClusterIconGenerator!
// let renderer = GMUDefaultClusterRenderer(mapView: mapViewFirst, clusterIconGenerator: iconGenerator)
if event_marker.position.latitude == self.latitude{
event_marker.iconView?.tintColor = UIColor.red
}
}
}){ (error) in
print(error.localizedDescription)
}
}
print(eventArray)
getClubs()
如果有人有解决方案,我将不胜感激我对编程还很陌生,而且我已经坚持了一段时间了。
这是 Google 文档 link:Customizing Marker Clusters
所以在 SWIFT 中回答:它不漂亮但很有效。
对于其他基本标记:
Google 中基本标记的文档是 link:
change the marker color
marker.icon = GMSMarker.markerImage(with: .black)
我正在构建一个 iOS 应用程序,我想在其中更改默认的红色 google 地图标记,不幸的是,我试图在整个互联网上查找,但找不到任何解决方案。 我的问题是我已经使用 gmaps utils 实现了 gmaps 集群,但我似乎无法找到更改 class POIItem 项目图标的方法。当尝试更改制造商外观时,会显示默认和自定义的两个标记。
所以这是一个代码片段: func getClubs(){
ref.child("Clubs").observe(.value, with: { (snapshot) in
for child in snapshot.children{
let snap = child as! DataSnapshot
let value = snap.value as? [String: Any]
//print(value!)
let name = value?["Name"] as? String
//let latitude = value?["Latitude"] as? String
//let longitude = value?["Longitude"] as? String
let contact = value?["Contact"] as? String
let prix = value?["Prix"] as? [String:Int]
var adresse = value?["Adresse"] as? String
if adresse == nil {
adresse = value?["Address"] as? String
}
var idFB = value?["ID Facebook"] as? Int
if idFB == nil {
idFB = value?["Facebook ID"] as? Int
}
//let clubFbId = String(describing: idFB)
//print(clubFbId)
print("\(idFB)")
let clubStruct: Club = Club(name: name!, adresse: adresse!, contact: contact!, clubIdFb: idFB!)
if prix != nil {
clubStruct.prix = prix
}
self.clubArray.updateValue(clubStruct, forKey: idFB!)
print(self.clubArray[idFB!]?.name)
}
}){ (error) in
print(error.localizedDescription)
}
ref.child("Events").observe(.value, with: { (snapshot) in
//var indice: Int = 1
for child in snapshot.children{
let snap = child as! DataSnapshot
//print(snap.key)
let event = snap.childSnapshot(forPath: "0").value as? [String:Any]
let place = snap.childSnapshot(forPath: "0").childSnapshot(forPath: "place").value as? [String:Any]
let clubFbId = place?["id"] as? String
let name = event?["name"] as? String
let start_time = event?["start_time"] as? String
let end_time = event?["end_time"] as? String
let eventFbId = event?["id"] as? String
let videoURL = event?["videoURL"] as? String
let timetable = event?["timetable"] as? [String:String]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.timeZone = TimeZone(abbreviation: "GMT+2:00")
let start = dateFormatter.date(from: start_time!)!
let end = dateFormatter.date(from: end_time!)!
if self.currentDate! > end {
continue
}
let location = snap.childSnapshot(forPath: "0").childSnapshot(forPath: "place").childSnapshot(forPath: "location").value as? [String:Any]
let latitude = location?["latitude"] as? CLLocationDegrees
let longitude = location?["longitude"] as? CLLocationDegrees
let eventStruct: Event = Event(latitude: latitude!, longitude: longitude!, clubIdFb: clubFbId!, eventIdFb: Int(eventFbId!)!, name: name!, start: start, end: end, idFirebase: snap.key)
if videoURL != nil {
eventStruct.videoURL = videoURL
}
if timetable != nil {
eventStruct.timetable = timetable
}
self.eventArray.updateValue(eventStruct, forKey: clubFbId!)
//print(self.eventArray[clubFbId!]?.name)
let event_marker = GMSMarker()
let clubimage = UIImage(named: "clubmarker")
let markerView = UIImageView(image: clubimage)
markerView.frame = CGRect(x: 0, y: 0, width: 58, height: 103)
event_marker.position = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
event_marker.map = mapViewFirst
event_marker.iconView = markerView
event_marker.isTappable = true
event_marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
let position = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
let event_item = POIItem(position:position, marker: event_marker)
self.clusterManager.add(event_item)
self.clusterManager.cluster()
// var iconGenerator : GMUDefaultClusterIconGenerator!
// let renderer = GMUDefaultClusterRenderer(mapView: mapViewFirst, clusterIconGenerator: iconGenerator)
if event_marker.position.latitude == self.latitude{
event_marker.iconView?.tintColor = UIColor.red
}
}
}){ (error) in
print(error.localizedDescription)
}
}
print(eventArray)
getClubs()
如果有人有解决方案,我将不胜感激我对编程还很陌生,而且我已经坚持了一段时间了。
这是 Google 文档 link:Customizing Marker Clusters
所以在 SWIFT 中回答:它不漂亮但很有效。
对于其他基本标记:
Google 中基本标记的文档是 link: change the marker color
marker.icon = GMSMarker.markerImage(with: .black)