gpt4 book ai didi

javascript - 如何在具有多个点(纬度和经度)的 react native map 上绘制折线?

转载 作者:行者123 更新时间:2023-11-28 03:33:33 27 4
gpt4 key购买 nike

嗨,我想在从 API 获取的多个位置之间绘制线条

这是我来自 API 的数据

(3) [{…}, {…}, {…}]
0:
CONTACTPERSONID: 2017011300
ENABLEPOLL: 0
HARDWAREID: 409792319815
LANDMARKID: 0
MESSAGETIME: "2دقيقه پيش"
MOVINGSTATE: "m"
NICKNAME: "ایران 78 - 875 ع 73"
POSDESCRIPTION: "ايران: استان كرمان - شهربابك"
SENTDATE: "18:14"
SENTDATE1: "1398-06-23 18:14:16"
SIGNATURE: "1-Normal"
SPEED: 51
TRUCKSTATE: "در حال حرکت"
VEHICLETYPE: 0
XPOINT: 55.13055
YPOINT: 30.128971
__proto__: Object
1: {HARDWAREID: 420474797787, NICKNAME: "رضا نوری پور ایران 62 - 374 ع 66", SENTDATE: "18:05", XPOINT: 51.2906383, YPOINT: 35.6798033, …}
2: {HARDWAREID: 2225434572, NICKNAME: "عابدین پور 938ع43", SENTDATE: "17:16", XPOINT: 48.33547, YPOINT: 38.26992, …}

X 点和 Y 点的纬度和经度

这是我要显示的代码:

<View style={{ height: hp('50%'), width: wp('100%') }}>
<MapView
provider={PROVIDER_GOOGLE}
onLayout={this.onMapLayout}
style={styles.containerMap}
initialRegion={{
latitude: this.props.data ? this.props.data[0].YPOINT : '',
longitude: this.props.data ? this.props.data[0].XPOINT : '',
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}} >
{this.state.isMapReady && this.props.data.map((value, index) => {
let poly = {
latitude: value.YPOINT,
longitude: value.XPOINT,
}
return < Polyline
strokeColor='#fd016f'
coordinates={poly}
/>
})
}

</MapView>

</View>

但出现此错误:**更新由 AIRMapPolyline 管理的 View 的属性“坐标”时出错 **

最佳答案

看起来这个错误可能是因为折线的坐标为空或未定义。尝试更改此代码:

  let poly = {
latitude: value.YPOINT,
longitude: value.XPOINT,
}

具有以下内容:

  let poly = {
latitude: value.YPOINT ? value.YPOINT : 0,
longitude: value.XPOINT ? value.XPOINT : 0,
}

希望这对您有帮助,请告诉我它是否适合您。

另请参阅相关内容:
Error while updating property 'coordinate' of a view managed by: AIRMapMarker (React native) https://github.com/react-native-community/react-native-maps/issues/1095

关于javascript - 如何在具有多个点(纬度和经度)的 react native map 上绘制折线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57936456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com