React native 使用React钩子更新位置时给出错误:更新时出错';地区';由以下人员管理的视图的名称:AIRMAP

React native 使用React钩子更新位置时给出错误:更新时出错';地区';由以下人员管理的视图的名称:AIRMAP,react-native,geolocation,react-hooks,React Native,Geolocation,React Hooks,我有这个错误,我不知道出了什么问题。我正在使用React挂钩(useState和useEffect)更新React本机应用程序中用户的当前位置 import React, {useEffect, useState} from 'react'; import MapView, {PROVIDER_GOOGLE} from 'react-native-maps'; import Geolocation from '@react-native-community/geolocation'; cons

我有这个错误,我不知道出了什么问题。我正在使用React挂钩(useState和useEffect)更新React本机应用程序中用户的当前位置

import React, {useEffect, useState} from 'react';
import MapView, {PROVIDER_GOOGLE} from 'react-native-maps';
import Geolocation from '@react-native-community/geolocation';

const MapScreen = () => {
   const [location, setLocation] = useState({
latitude: 18.9712,
longitude: -72.2852,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
 });

useEffect(() => {
Geolocation.getCurrentPosition(position => {
  const region = {
    latitude: position.coords.latitude,
    longitude: position.coords.longitude,
    latitudeDelta: 0.001,
    longitudeDelta: 0.001,
  }
  setLocation({region})
})

}, [])
return (
<MapView
  provider={PROVIDER_GOOGLE}
  style={{flex: 1}}
  showsUserLocation={true}
  region={location}

/>
)
}

export default MapScreen
import React,{useffect,useState}来自“React”;
从“react native maps”导入MapView,{PROVIDER_GOOGLE};
从“@react native community/Geolocation”导入地理位置;
常量映射屏幕=()=>{
const[location,setLocation]=useState({
纬度:18.9712,
经度:-72.2852,
纬度德尔塔:0.0922,
纵向德尔塔:0.0421,
});
useffect(()=>{
Geolocation.getCurrentPosition(位置=>{
常量区域={
纬度:位置。坐标。纬度,
经度:position.coords.longitude,
纬度德尔塔:0.001,
纵向德尔塔:0.001,
}
setLocation({region})
})
}, [])
返回(
)
}
导出默认映射屏幕

我认为问题就在这里

setLocation({region})
这里,
区域
是一个对象,因此它成为

setLocation({{
    latitude: position.coords.latitude,
    longitude: position.coords.longitude,
    latitudeDelta: 0.001,
    longitudeDelta: 0.001,
}})
设置状态不正确。

您只需要设置区域

setLocation(region)

我认为问题在于
设置位置({region})
。试试这个
setLocation(region)
没错,请添加答案,这样我就可以接受它作为正确答案,而不仅仅是一个注释。谢谢