[英]React-Native-Maps how to draw polylines From Array List?
我已经开始使用https://github.com/airbnb/react-native-maps并且没有运气从 map 上的数组坐标数组中绘制折线。
我不确定我是否正确传递了坐标数组。
这就是我渲染折线的方式:
这是包含坐标的 api 链接: https://run.mocky.io/v3/e42d76ce-2ac8-4199-9f2c-e5b611960d38
我有这样的代码。
<MapView
style={styles.mapStyle}
provider={PROVIDER_GOOGLE}
minZoomLevel={0}
showsTraffic={false}
showsBuildings={true}
followUserLocation={false}
loadingEnabled={true}
showsUserLocation={true}
loadingIndicatorColor={'green'}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
zoomEnabled={true}
showsUserLocation={true}>
{
speed.map((d) =>
d.segments.map((c) => (
<Polyline
coordinates={c.coordinate}
strokeColor="#000" the map-provider
strokeWidth={6}>
<Marker
coordinate={{latitude: 37.8025259, longitude: -122.4351431}}
title="Flatiron School Atlanta"
description="This is where the magic happens!"></Marker>
</Polyline>
)),
)}
</MapView>
我有这样的坐标,
{"coordinates":[[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867],[43.43522206128157,-79.73892179139867]]}
谢谢你的帮助
Polyline中的坐标是一个 LatLng 数组
键入 LatLng { 纬度:数字,经度:数字,}
所以这样的事情应该有效:
d.segments.map((c) =>
<Polyline
coordinates={c.coordinates.map(c => ({latitude: c[0], longitude: c[1]}))}
strokeColor="#000"
strokeWidth={6}>
</Polyline>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.