我"react-native-maps": "0.29.4"在組件上使用 , 和 google 提供程式Map。
出于某種原因,animateCamera僅在 ios 上使用且僅在某些情況下使用(主要是在重繪 應用程式后,例如在初始獲得用戶位置 GPS 許可后將 rtl 切換為 ltr)具有偏移量,該偏移量應該位于中心位置左上角
https://youtu.be/3cLeZSIAaVk
視頻顯示使用handlePressMyLocation功能時的包
const handleAnmiateToRegion = useCallback((center: IMapLocation, zoom: number = undefined) => {
mapRef.current
? mapRef.current.animateCamera({ center, zoom })
: setTimeout(() => {
handleAnmiateToRegion(center, zoom)
}, 100)
}, [])
const handlePressMyLocation = useCallback(() => {
handleAnmiateToRegion(location)
}, [location.latitude, location.longitude])
再一次,這在 android 上永遠不會發生,有時在 ios 上它也可以正常作業,但如果會話有這個錯誤,它會一直發生并且在所有animateCamera使用中都會發生(有更多這樣的情況,handleAnmiateToRegion因為 init focus 縮放或在按下某些標記的情況下)
有什么想法嗎?還嘗試更改animateCamera為animateToRegion,并在之后使用 12 位.而不是 5 位呼叫函式(由 給出Geolocation.watchPosition),但發生相同的錯誤)
提前致謝!
(如果更多代碼會有所幫助,請寫在評論中,我會添加)
uj5u.com熱心網友回復:
出于某種原因,僅在我獲得用戶位置后渲染地圖(memo用于確保它確實發生并避免不必要的重新渲染)并設定initialRegionprop onMap修復了問題
uj5u.com熱心網友回復:
<MapView
provider={PROVIDER_GOOGLE}
key={this.state.forceRefresh}
style={styles.gmapView}
showsUserLocation
ref={(ref) => (this.mapView = ref)}
followUserLocation
showsMyLocationButton
snappedminZoomLevel={Platform.OS == "ios" ? this.state.zoom : 12}
/* minZoomLevel={11}
maxZoomLevel={17} */
showsMyLocationButton={false}
initialRegion={{
latitude: latlong.lat || currentLocation.latitude,
longitude: latlong.lng || currentLocation.longitude,
latitudeDelta: this.state.latitudeDelta,
longitudeDelta: this.state.longitudeDelta,
}}
onRegionChange={(data) =>
this.setState(
{
newLatitude: data.latitude,
newLongitude: data.longitude,
zoom:Math.round(Math.log(360 / data.longitudeDelta) / Math.LN10),
latitudeDelta: data.latitudeDelta,
longitudeDelta: data.longitudeDelta,
},
() => {
console.log("data ==> " JSON.stringify(data))
}
)
}
onPress={(e) =>{
this.animate(e)
}
}
>
</MapView>
animate(e){
let lat = e?.nativeEvent?.coordinate?.latitude 0.004000;
let long = e?.nativeEvent?.coordinate?.longitude - 0.004000;
let r = {
latitude: lat,
longitude: long,
latitudeDelta: 0.38,//this.state.latitudeDelta,
longitudeDelta: 0.28,//this.state.longitudeDelta,
};
this.mapView.animateToRegion(r, 300);}
你能試試這個嗎?可能對你有幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/435873.html
上一篇:如何更新標記位置谷歌地圖顫動
