Planovac, zobrazeni vzdusnych prostoru

This commit is contained in:
Michal Kváček
2024-03-21 16:40:41 +01:00
parent 691bd4c7c5
commit 02b839674e
15 changed files with 450 additions and 68 deletions
+41
View File
@@ -0,0 +1,41 @@
import {ref} from "vue";
import axios from "axios";
export const useGeocode = (emits) => {
const center = ref({
lat: 50.1314,
lng: 14.5256
});
const zoom = ref(10);
const emitModels = (lat, lng) => {
emits("update:gpsLatitude", lat);
emits("update:gpsLongitude", lng);
}
const searchGeocode = (address) => {
return axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURI(address)}&key=${process.env.GOOGLE_MAPS_API_KEY}`).then(response => {
if (response.data.status !== 'OK') {
return null;
}
return response.data.results;
});
}
const setCoordinatesFromGeocode = (address) => {
// TODO: odstranit a nahradit za searchGeocode! Vlastne cela tato composable by sla nahradit
axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURI(address)}&key=${process.env.GOOGLE_MAPS_API_KEY}`).then(response => {
if (response.data.status !== 'OK') {
emits("notFound", address);
return null;
}
center.value = response.data.results[0].geometry.location;
emitModels(center.value.lat, center.value.lng);
zoom.value = 13;
});
}
return {emitModels, setCoordinatesFromGeocode, zoom, center, searchGeocode}
}