我在地图组件中使用
GeolocateControl
将地图移动到用户当前位置。它可以工作,但 showUserLocation
道具在地图的第一次渲染中不起作用。我尝试使用假 setState 重新渲染它,但没有成功。我该怎么做才能在第一次渲染中显示用户当前位置的蓝色圆圈?
<GeolocateControl
ref={geoControlRef}
style={{ display: 'none' }}
fitBoundsOptions={{
zoom: 11,
}}
trackUserLocation
showAccuracyCircle={false}
showUserLocation
showUserHeading={geoControlRef?.current && true}
onGeolocate={onGeoLocate}
positionOptions={{ enableHighAccuracy: true }}
/>
这就是我正在使用的,但是我无法显示此链接中所示的用户标题,如果您可以帮助我的话 反应地图-GL:7.0.15
<Map
ref={mapViewRef}
mapStyle={currentMapStyle}
transformRequest={transformRequest}
>
<GeolocateControl
position="bottom-right"
ref={geolocateControlRef}
positionOptions={{ enableHighAccuracy: true }}
showUserLocation
showAccuracyCircle={false}
onGeolocate={onGeoLocate} // function that focuses the map on the user's location
onError={onGeoLocateError}
showUserHeading
trackUserLocation
/>
/>