MapView.Polyline 在 react native with expo 中抛出错误(我正在使用 android 进行测试)

MapView.Polyline in react native with expo throws an error (I'm testing with an android)

我正在尝试用多段线画一条线,但出现此错误:

更新 属性 管理的视图的“lineCap”时出错:AIRMapPolyline 无效的 尝试在空对象引用

上调用虚方法‘void com.google.android.gms.maps.model..u.g(java.util.List)

这是代码:

           <MapView
                style={styles.map}
                initialRegion={{
                    latitude: initialLocation.latitude,
                    longitude: initialLocation.longitude,
                    latitudeDelta: 0.01,
                    longitudeDelta: 0.01
                }}
            >
                <Circle
                    center={currentLocation.coords}
                    radius={30}
                    strokeColor='rgba(158, 158, 255, 1.0)'
                    fillColor='rgba(0, 0, 255, 0.3)'
                />
                {drawLine && (
                    <MapView.Polyline
                        coordinates={locations.map(loc => {
                            return {
                                latitude: loc.coords.latitude,
                                longitude: loc.coords.longitude
                            };
                        })}
                        strokeColor='red'
                        strokeWidth={1}
                    />
                )}
            </MapView>

地图绘制正常,圆圈显示正常,但是当我尝试绘制一条线时,它会抛出那个可怕的错误。

对象数组已经检查

https://github.com/rafaelsoteldosilva/maptest

会是什么?

拉斐尔

您只需添加:

lineDashPattern={[1]}

作为折线组件的属性,例如:

<Polyline
   style={{}}
   coordinates={route}
   strokeColor={#000}
   strokeWidth={3}
   lineDashPattern={[1]}
/>

你应该可以开始了