首页 > 解决方案 > 响应谷歌地图 onMarkerClick 事件未在移动设备中触发

问题描述

                         initialCenter={{
                             lat: lat,
                             lng: lng
                         }}
                         onClick={this.onMapClicked}
                         zoom={zoom}>

                        {this.state.marker.map((data, index) => {

                                return (


                                    <Marker
                                        ref={this.onMarkerMounted}
                                        key={index}

                                        onClick={this.onMarkerClick}

                                        name={data.name}
                                        phone={data.phone}
                                        icon={{
                                            url: data.icon,
                                            anchor: new this.props.google.maps.Point(20, 20),
                                            scaledSize: new this.props.google.maps.Size(80, 80)
                                        }}
                                        position={{"lat": data.lat, "lng": data.lng}}/>

                                )
                            }
                        )}
                        <InfoWindow
                            marker={this.state.activeMarker}
                            visible={this.state.showingInfoWindow}
                            onClose={this.onClose}
                        >
                            <View style={{width: 100, height: 20}}>
                                <Text style={{
                                    fontWeight: '600',
                                    fontSize: 14,
                                    color: "#54AD58"
                                }}>{this.state.selectedPlace.phone}</Text>
                            </View>
                        </InfoWindow>
                    </Map>

在 React google maps 中,Marker Touch 事件在移动视图中不起作用。相同的功能在桌面视图上运行良好。但是当我为 mobileview 调用这个函数时,它不能正常工作。

如果我更改了名为 this.onMarkerClick() 的函数,这应该在我触摸地图时调用该函数,但这将无法正常工作。onMapclicked 事件在移动视图和桌面视图中工作。我不知道是什么问题。。

标签: javascriptreactjsreact-native

解决方案


推荐阅读