เช็คเวลาต้องลงเวลาเข้าหรือออกงาน (USER)
This commit is contained in:
parent
3083ea8dcb
commit
07b02a7818
4 changed files with 128 additions and 22 deletions
|
|
@ -7,10 +7,11 @@ const center = ref<any>()
|
|||
const location = ref<string>('')
|
||||
const test = ref()
|
||||
|
||||
// hook
|
||||
onMounted(() => {
|
||||
findNearestPlace()
|
||||
})
|
||||
const emit = defineEmits(["update:location"]);
|
||||
const updateLocation = (location: any, namePOI: string) => {
|
||||
// ส่ง event ไปยัง parent component เพื่ออัพเดทค่า props
|
||||
emit("update:location", location, namePOI);
|
||||
};
|
||||
|
||||
// หาตำแหน่ง
|
||||
function findNearestPlace() {
|
||||
|
|
@ -25,7 +26,6 @@ function findNearestPlace() {
|
|||
// ส่ง Location ไปยัง API เพื่อหาสถานที่ที่ใกล้ที่สุด
|
||||
findNearestPlaceFromAPI(userLocation)
|
||||
center.value = userLocation
|
||||
console.log(center.value)
|
||||
},
|
||||
(error) => {
|
||||
console.error(error)
|
||||
|
|
@ -36,6 +36,8 @@ function findNearestPlace() {
|
|||
console.error('เบราว์เซอร์ไม่รองรับการระบุตำแหน่ง')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function findNearestPlaceFromAPI(userLocation: any) {
|
||||
const placesService = new google.maps.places.PlacesService(
|
||||
document.createElement('div')
|
||||
|
|
@ -49,15 +51,22 @@ function findNearestPlaceFromAPI(userLocation: any) {
|
|||
|
||||
placesService.nearbySearch(request, (results: any, status: any) => {
|
||||
if (status === google.maps.places.PlacesServiceStatus.OK) {
|
||||
console.log('Nearby places:', results[0])
|
||||
// console.log('Nearby places:', results[0])
|
||||
const place = results[0]
|
||||
location.value = place.name
|
||||
test.value = place.geometry.location
|
||||
updateLocation(center.value,location.value)
|
||||
|
||||
} else {
|
||||
console.error('Error fetching nearby places:', status)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// hook
|
||||
onMounted(() => {
|
||||
findNearestPlace()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue