From 94d33839c7adc078de3dc9a23b6deb03f2d68e1d Mon Sep 17 00:00:00 2001 From: Sofiane Abou Abderrahim Date: Tue, 17 Oct 2023 15:02:02 +0300 Subject: [PATCH] set navigator.geolocation.getCurrentPosition in locateUserHandler and instantied PlaceFinder --- src/SharePlace.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/SharePlace.js b/src/SharePlace.js index bfc965f..6d060ad 100644 --- a/src/SharePlace.js +++ b/src/SharePlace.js @@ -7,7 +7,33 @@ class PlaceFinder { addressForm.addEventListener('submit', this.findAddressHandler); } - locateUserHandler() {} + locateUserHandler() { + if (!navigator.geolocation) { + alert( + 'Location feature is not available in your browser - please use a more modern browser or manually enter an address.' + ); + return; + } + navigator.geolocation.getCurrentPosition( + successResult => { + // console.log(successResult); + const coordinates = { + lat: successResult.coords.latitude + Math.random() * 50, // to not display my current position + lng: successResult.coords.longitude + Math.random() * 50 // to not display my current position + }; + console.log(coordinates); + }, + error => { + alert( + 'Could not locate you unfortunately. Please enter an address manually!' + ); + } + ); + } findAddressHandler() {} } + +const placeFinder = new PlaceFinder(); +// we need to make sure that we of course trigger our constructor here for the PlaceFinder +// and we do that by instantiating PlaceFinder.