Skip to content

Commit

Permalink
set navigator.geolocation.getCurrentPosition in locateUserHandler and…
Browse files Browse the repository at this point in the history
… instantied PlaceFinder
  • Loading branch information
sofiane-abou-abderrahim committed Oct 17, 2023
1 parent 58f5d3c commit 94d3383
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/SharePlace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 94d3383

Please sign in to comment.