fixes: directions api change
This commit is contained in:
@@ -26,12 +26,19 @@ export default function useDirectionsRender() {
|
||||
};
|
||||
|
||||
const getDirections = async (originCoords, destinationCoords) => {
|
||||
const originLatLng = `${originCoords.lat},${originCoords.lng}`;
|
||||
const destinationLatLng = `${destinationCoords.lat},${destinationCoords.lng}`;
|
||||
// const originLatLng = `${originCoords.lat},${originCoords.lng}`;
|
||||
// const destinationLatLng = `${destinationCoords.lat},${destinationCoords.lng}`;
|
||||
try {
|
||||
let url = `https://maps.googleapis.com/maps/api/directions/json?origin=${originLatLng}&destination=${destinationLatLng}&mode=driving&key=${mapKey}`;
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
const directionsService = new google.maps.DirectionsService();
|
||||
// const origin = google.maps.LatLng(originCoords.lat, originCoords.lng)
|
||||
// const destination = google.maps.LatLng(destinationCoords.lat, destinationCoords.lng)
|
||||
const request = {
|
||||
origin: {lat: Number.parseFloat(originCoords.lat), lng: Number.parseFloat(originCoords.lng)},
|
||||
destination: {lat: Number.parseFloat(destinationCoords.lat), lng: Number.parseFloat(destinationCoords.lng)},
|
||||
travelMode: 'DRIVING'
|
||||
};
|
||||
const data = await directionsService.route(request)
|
||||
|
||||
let polylines = [];
|
||||
if (data.routes && data.routes.length > 0) {
|
||||
const steps = data.routes[0].legs[0].steps;
|
||||
@@ -44,6 +51,7 @@ export default function useDirectionsRender() {
|
||||
})
|
||||
})
|
||||
});
|
||||
console.log({polylines})
|
||||
return polylines;
|
||||
} else {
|
||||
return [];
|
||||
@@ -53,6 +61,36 @@ export default function useDirectionsRender() {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
// const getDirections = async (originCoords, destinationCoords) => {
|
||||
// const originLatLng = `${originCoords.lat},${originCoords.lng}`;
|
||||
// const destinationLatLng = `${destinationCoords.lat},${destinationCoords.lng}`;
|
||||
// try {
|
||||
// let url = `https://maps.googleapis.com/maps/api/directions/json?origin=${originLatLng}&destination=${destinationLatLng}&mode=driving&key=${mapKey}`;
|
||||
// // let url = `https://maps.googleapis.com/maps/api/directions/json?origin=${originLatLng}&destination=${destinationLatLng}&mode=driving&key=${mapKey}`;
|
||||
// const response = await fetch(url);
|
||||
// const data = await response.json();
|
||||
// let polylines = [];
|
||||
// if (data.routes && data.routes.length > 0) {
|
||||
// const steps = data.routes[0].legs[0].steps;
|
||||
// steps.forEach(item => {
|
||||
// const points = decode(item.polyline.points);
|
||||
// points.forEach(poly => {
|
||||
// polylines.push({
|
||||
// lat: poly[0],
|
||||
// lng: poly[1]
|
||||
// })
|
||||
// })
|
||||
// });
|
||||
// console.log({polylines})
|
||||
// return polylines;
|
||||
// } else {
|
||||
// return [];
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.log(error);
|
||||
// return [];
|
||||
// }
|
||||
// };
|
||||
|
||||
return {
|
||||
originCoords,
|
||||
|
||||
Reference in New Issue
Block a user