swift 为GMSMarker设置自定义accessibilityIdentifier

clj7thdc  于 2023-06-21  发布在  Swift
关注(0)|答案(4)|浏览(96)

我使用谷歌MapAPI来制作Map和标记。
我通过以下设置启用标记的可访问性:mapView.accessibilityElementsHidden = false
现在我在Map上的所有自定义标记都有辅助功能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

aor9mmx1

aor9mmx11#

试试这个

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)
}
drnojrws

drnojrws2#

如果你用的是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)
yrdbyhpb

yrdbyhpb3#

我也有类似的问题,GMSMarker没有accessibilityIdentifier。我所做的是,将accessibilityIdentifier设置为icon或iconView,例如:

marker.icon?.accessibilityIdentifier = "something" or
marker.iconView?.accessibilityIdentifier = "something"
wpx232ag

wpx232ag4#

如下设置标识符(无accessibilityIdentifier访问权限)

marker.accessibilityLabel = "markerPinId"

在UITest中阅读

var element = app.buttons["markerPinId"]

确保同时添加[accessibilityElementsHidden = false]

相关问题