-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.js
35 lines (31 loc) · 1.06 KB
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { GoogleMap, LoadScript, Polyline } from '@react-google-maps/api';
const JourneyHistory = ({ userId }) => {
const [journeys, setJourneys] = useState([]);
useEffect(() => {
axios.get(`/journeys/${userId}`).then(response => setJourneys(response.data));
}, [userId]);
return (
<div>
{journeys.map(journey => (
<div key={journey._id}>
<h3>Journey from {journey.startLocation} to {journey.endLocation}</h3>
<LoadScript googleMapsApiKey="">
<GoogleMap
mapContainerStyle={{ height: "400px", width: "800px" }}
center={{ lat: 0, lng: 0 }}
zoom={8}
>
<Polyline
path={journey.route.map(coord => ({ lat: coord.lat, lng: coord.lng }))}
options={{ strokeColor: "#FF0000" }}
/>
</GoogleMap>
</LoadScript>
</div>
))}
</div>
);
};
export default JourneyHistory;