i have json
{
"status": 200,
"error": false,
"driver": [
{
"id": "7",
"name": "Kevin",
"lat": "-6.2616031",
"lon": "106.8424822"
},
{
"id": "9",
"name": "jhon",
"lat": "-6.20032449",
"lon": "106.6372306"
},
}
here I am capturing or retrieving json data and displaying it on maps when i show i get an error problem which is:
Value for latitude cannot be cast from String to Double in react-native
where is the error ? this is my code
componentDidMount() {
fetch('https://example.com/myjson')
.then(res => res.json())
.then(data => {
this.setState({ data: data.driver })
})
.catch(console.error)
}
mapMarkers = () => {
return this.state.data.map((driver) => <MapView.Marker
key={driver.id}
coordinate={{ "latitude": driver.lat, "longitude": driver.lon }}
title={driver.name}
description={driver.division}
/>)
}
render() {
return (
<View style={styles.container}>
<View style={{ flex: 2 }}>
<MapView
style={{ flex: 1, width: window.width }} //window pake Dimensions
Region={{
latitude: 106.8424822,
longitude: -6.2616031,
latitudeDelta: 70,
longitudeDelta: 45
}} >
{this.mapMarkers()}
</MapView>
</View>
</View>
);
}