Planovac, zobrazeni vzdusnych prostoru
This commit is contained in:
@@ -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}
|
||||
}
|
||||
Reference in New Issue
Block a user