如何在React Native中从lat,long数组映射多个标记 [英] How to map multiple Markers from lat,long array in react native
问题描述
To get the coordinate array, I used the answer from here
它允许我使用{"lat":any"lon":any}制作数组
it allows me to make an array with {"lat":any "lon":any}
我正在尝试制作一个循环,在其中可以标记每个纬度和经度,我尝试了
I'm trying to make a loop where I can mark every lat and lon, I tried this
{LatLongArray.map((LatLongArray,index) => {
return (
<MapView.Marker
key = {index}
coordinate = {{ LatLongArray}}
>
</MapView.Marker>
);
})}
但是我得到的错误是lat和lon值未定义我还得到每个子组件都应该具有唯一键的错误.
But I get the error that the lat and lon value is undefined I also get the error that each child component should have a unique key.
循环在MapView组件内部
The loop is inside a MapView component
需要帮助,谢谢.
这是错误和堆栈跟踪.
[Mon Feb 01 2021 11:38:27.890] ERROR Warning: Failed prop type: The prop `coordinate.latitude` is marked as required in `MapMarker`, but its value is `undefined`.
MapMarker@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:127169:36
in AirportMap (at HomeScreen.js:16)
in RCTView (at View.js:34)
in View (at SafeAreaView.js:41)
in ForwardRef(SafeAreaView) (at HomeScreen.js:15)
in HomeScreen (at SceneView.tsx:122)
in StaticContainer
in StaticContainer (at SceneView.tsx:115)
in EnsureSingleNavigator (at SceneView.tsx:114)
in SceneView (at useDescriptors.tsx:153)
in RCTView (at View.js:34)
in View (at CardContainer.tsx:245)
in RCTView (at View.js:34)
in View (at CardContainer.tsx:244)
in RCTView (at View.js:34)
in View (at CardSheet.tsx:33)
in ForwardRef(CardSheet) (at Card.tsx:573)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:165)
in AnimatedComponent (at createAnimatedComponent.js:215)
in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:555)
in PanGestureHandler (at GestureHandlerNative.tsx:13)
in PanGestureHandler (at Card.tsx:549)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:165)
in AnimatedComponent (at createAnimatedComponent.js:215)
in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:544)
in RCTView (at View.js:34)
in View (at Card.tsx:538)
in Card (at CardContainer.tsx:206)
in CardContainer (at CardStack.tsx:620)
in RCTView (at View.js:34)
in View (at Screens.tsx:84)
in MaybeScreen (at CardStack.tsx:613)
in RCTView (at View.js:34)
in View (at Screens.tsx:54)
in MaybeScreenContainer (at CardStack.tsx:495)
in CardStack (at StackView.tsx:462)
in KeyboardManager (at StackView.tsx:458)
in SafeAreaProviderCompat (at StackView.tsx:455)
in RCTView (at View.js:34)
in View (at GestureHandlerRootView.android.js:26)
in GestureHandlerRootView (at StackView.tsx:454)
in StackView (at createStackNavigator.tsx:87)
in StackNavigator (at DrawerNavigationRoutes.js:23)
in homeScreenStack (at SceneView.tsx:122)
in StaticContainer
in StaticContainer (at SceneView.tsx:115)
in EnsureSingleNavigator (at SceneView.tsx:114)
in SceneView (at useDescriptors.tsx:153)
in RCTView (at View.js:34)
in View (at ResourceSavingScene.tsx:68)
in RCTView (at View.js:34)
in View (at ResourceSavingScene.tsx:63)
in ResourceSavingScene (at DrawerView.tsx:183)
in RCTView (at View.js:34)
in View (at src/index.native.js:123)
in ScreenContainer (at DrawerView.tsx:162)
in RCTView (at View.js:34)
in View (at Drawer.tsx:645)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:240)
in AnimatedComponent(View) (at Drawer.tsx:638)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:240)
in AnimatedComponent(View) (at Drawer.tsx:628)
in PanGestureHandler (at GestureHandlerNative.tsx:13)
in PanGestureHandler (at Drawer.tsx:619)
in DrawerView (at DrawerView.tsx:215)
in SafeAreaProviderCompat (at DrawerView.tsx:213)
in RCTView (at View.js:34)
in View (at GestureHandlerRootView.android.js:26)
in GestureHandlerRootView (at DrawerView.tsx:212)
in DrawerView (at createDrawerNavigator.tsx:47)
in DrawerNavigator (at DrawerNavigationRoutes.js:76)
in DrawerNavigatorRoutes (at SceneView.tsx:122)
in StaticContainer
in StaticContainer (at SceneView.tsx:115)
in EnsureSingleNavigator (at SceneView.tsx:114)
in SceneView (at useDescriptors.tsx:153)
in RCTView (at View.js:34)
in View (at CardContainer.tsx:245)
in RCTView (at View.js:34)
in View (at CardContainer.tsx:244)
in RCTView (at View.js:34)
in View (at CardSheet.tsx:33)
in ForwardRef(CardSheet) (at Card.tsx:573)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:165)
in AnimatedComponent (at createAnimatedComponent.js:215)
in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:555)
in PanGestureHandler (at GestureHandlerNative.tsx:13)
in PanGestureHandler (at Card.tsx:549)
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:165)
in AnimatedComponent (at createAnimatedComponent.js:215)
in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:544)
in RCTView (at View.js:34)
in View (at Card.tsx:538)
in Card (at CardContainer.tsx:206)
in CardContainer (at CardStack.tsx:620)
in RCTView (at View.js:34)
in View (at Screens.tsx:84)
in MaybeScreen (at CardStack.tsx:613)
in RCTView (at View.js:34)
in View (at Screens.tsx:54)
in MaybeScreenContainer (at CardStack.tsx:495)
in CardStack (at StackView.tsx:462)
in KeyboardManager (at StackView.tsx:458)
in RNCSafeAreaProvider (at SafeAreaContext.tsx:74)
in SafeAreaProvider (at SafeAreaProviderCompat.tsx:42)
in SafeAreaProviderCompat (at StackView.tsx:455)
in GestureHandlerRootView (at GestureHandlerRootView.android.js:31)
in GestureHandlerRootView (at StackView.tsx:454)
in StackView (at createStackNavigator.tsx:87)
in StackNavigator (at App.js:44)
in EnsureSingleNavigator (at BaseNavigationContainer.tsx:409)
in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
in ThemeProvider (at NavigationContainer.tsx:90)
in ForwardRef(NavigationContainer) (at App.js:42)
in App (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)
推荐答案
我解决了非常简单的问题
I fixed the problem it was pretty easy
由于react-native-maps api需要纬度"和经度"作为数组中的键.
Since the react-native-maps api takes "latitude" and longitude" as keys in the array.
我替换了所有的纬度"和"lon"表示并绘制了所有的机场.
I replaced all the "lat" and "lon" and it plots all the airports.
这篇关于如何在React Native中从lat,long数组映射多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!