diff --git a/index.html b/index.html index b9d284d..f939995 100644 --- a/index.html +++ b/index.html @@ -9,5 +9,6 @@
+ diff --git a/src/components/MapCheckin.vue b/src/components/MapCheckin.vue index c505458..de208fd 100644 --- a/src/components/MapCheckin.vue +++ b/src/components/MapCheckin.vue @@ -7,10 +7,11 @@ const center = ref() const location = ref('') 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() +})