From 07b02a781874b7ba95217edaebe1784dbf617c30 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 15 Nov 2023 18:08:42 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B9=80?= =?UTF-8?q?=E0=B8=A7=E0=B8=A5=E0=B8=B2=E0=B8=95=E0=B9=89=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B8=A5=E0=B8=87=E0=B9=80=E0=B8=A7=E0=B8=A5=E0=B8=B2=E0=B9=80?= =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=B2=E0=B8=AB=E0=B8=A3=E0=B8=B7=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=87=E0=B8=B2=E0=B8=99=20(USER)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 1 + src/components/MapCheckin.vue | 21 +++++-- src/stores/mixin.ts | 16 +++++ src/views/HomeView.vue | 112 +++++++++++++++++++++++++++++----- 4 files changed, 128 insertions(+), 22 deletions(-) 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() +})