2017-09-01 2 views
0

Je suis en train de créer une application iOS où je voudrais changer les marqueurs google maps rouges par défaut, malheureusement, j'ai essayé de regarder partout sur Internet et ne trouve aucune solution. Mon problème est que j'ai implémenté le clustering gmaps avec les utilitaires gmaps, mais je n'arrive pas à trouver un moyen de changer l'icône d'un élément de la classe POIItem. Lorsque vous essayez de modifier l'apparence des fabricants, les deux marqueurs sont affichés, la valeur par défaut et la coutume.Changement google maps Marqueurs POIItem

Alors, voici un extrait de code: 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() 

Si quelqu'un a une solution, il serait très apprécié que je suis tout à fait nouveau à la programmation et il a été un moment que je suis coincé avec ça pendant un moment.

Below is a screenshot of my output

Répondre