1

我正在尝试在地图上显示相对于特定坐标的图标,但我不断抛出此错误,然后是:

removedChildren count(0) was not what we expected (1)

这将不允许图钉显示在地图上。下面是我的代码:

const [restaurant_Latitude, setRestaurantLatitude] = useState(0)
const [restaurant_Longitude, setRestaurantLongitude] = useState(0)
const [restaurantPositionError, setRestaurantPositionError] = useState(null)

使用 react-native-svg 创建图标

const restaurantIcon = () =>{
      return(
        <Svg
          height = {30}
          width = {30}
        >
          <Ellipse
            cx="10"
            cy="10"
            rx="10"
            ry="10"
            fill="red"
            stroke="#fff"
            strokeWidth="2"
          />

        </Svg>
        )
    }

//useEffect 获取餐厅坐标

useEffect(() =>{

...

displayRestaurantInfo = async () =>{
 let restaurantInfo = client_instance.getFoodInfo()

   setRestaurantLatitude(restaurantInfo.latitude)
   setRestaurantLongitude(restaurantInfo.longitude)
   setRestaurantPositionError(null)
}

displayRestaurantInfo()

)
}

...

//如何在 MapView 中呈现

return(
      
        <MapView>

            <Marker 
                coordinate={ 
                    {latitude: restaurantLatitude,
                     longitude: restaurantLongitude,
                     error: position_error,
                    }}
              >
                <View>
                  {(restaurantIcon())}
                </View>
              </Marker>
</MapView>
4

0 回答 0