Error when create react native maps

Hello. I’m startting build a react-native maps with expo. but when i get directions bettween two points by polyline, i got this error:
TypeError: undefined is not an object (evaluating ‘respJson.routes[0].overview_polyline’)
Here is my code:
let resp = await fetch(https://maps.googleapis.com/maps/api/directions/json?origin=${ startLoc }&destination=${ destinationLoc }&key=$(key));
let respJson = await resp.json();
let points = Polyline.decode(respJson.routes[0].overview_polyline.points);
let coords = points.map(point => {
return {
latitude: point[0],
longitude: point[1]
}
})
this.setState({coords: coords})
return coords;
Thank you everyone;

Hi

It would be a bit easier to see what your code is doing if you make it into a code block :slight_smile:

```
code
here
```

What does respJson look like? e.g.:

  let respJson = await resp.json();
  console.log(JSON.stringify(respJson))
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.