为GMSMarker设置自定义accessibilityIdentifier

时间:2017-02-06 05:21:54

标签: swift google-maps-sdk-ios

我使用Google Maps Api来制作地图和标记。

我通过设置mapView.accessibilityElementsHidden = false

启用标记的辅助功能

现在,我在地图上的所有自定义标记都具有辅助功能ID,例如:myappname.GMSPlaceMarker_somenumbers,例如myappname.GMSPlaceMarker_0x600000170200

如何为所有引脚设置一个accessibilityIdentifier,例如Map pin

我已经尝试过:

  • marker.accessibilityLabel = "Map pin"但它设置了label值,而不是id
  • marker.title = "Map pin"没有任何变化
  • marker.setValue("Map pin", forKey: "accessibilityIdentifier")没有任何变化

我的markerlet marker = GMSPlaceMarker(),其中class GMSPlaceMarker: GMSMarker

2 个答案:

答案 0 :(得分:1)

试试这个,

func markPoints() {
    var annotationCoord : CLLocationCoordinate2D = CLLocationCoordinate2D()
    annotationCoord.latitude = (selectedLocation.latitude as NSString).doubleValue
    annotationCoord.longitude = (selectedLocation.longitude as NSString).doubleValue

    let annotationPoint: MKPointAnnotation = MKPointAnnotation()
    annotationPoint.coordinate = annotationCoord
    annotationPoint.title = selectedLocation.name
    annotationPoint.subtitle = "Anand: 7348858742"
    theMap.addAnnotation(annotationPoint)
}

答案 1 :(得分:0)

如果你正在使用 swift 4 试试这个,

    var destionationMarker: GMSMarker!

    func setupDriverMarker(coordinate: CLLocationCoordinate2D) {            
        destionationMarker = GMSMarker(position: coordinate)
        for pin: GMSMarker in self.DestinationMarkerArray {
            if pin.userData as! String == "drivermarker" {
                pin.map = nil
            }
        }            
        destionationMarker.title = "Your Title"
        destionationMarker.appearAnimation = GMSMarkerAnimation.pop
        let images = #imageLiteral(resourceName: "ic_map_marker")
        destionationMarker.icon = images
        destionationMarker.userData = "drivermarker"
        destionationMarker.opacity = 1
        destionationMarker.map = journeyMapView

    }

像这样实施

DriverLocation = CLLocationCoordinate2D(latitude: 21.2362546, longitude: 72.8751862)
setupDriverMarker(coordinate: DriverLocation)