-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the Geolocation (current location of user) Feature #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature works great! I noted some code changes I'd like to see before merging. Please let me know via slack if you have any questions!
src/components/map/GoogleMap.svelte
Outdated
@@ -44,6 +45,43 @@ | |||
if (browser) { | |||
window.addEventListener('themeChange', handleThemeChange); | |||
} | |||
|
|||
const locationButton = document.createElement('button'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to see this extracted out into a reusable component. We'll want to support different map backends at some point (Mapbox, OSM, Bing, Apple, etc.), and I want to make sure that we can reuse as much functionality across them as possible.
Once it's a reusable component, it should be straightforward (I hope) to use the Font Awesome package to display the crosshairs icon instead of loading the entire package from a CDN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I will make sure to create a reusable component for using in the future.
src/components/map/GoogleMap.svelte
Outdated
document.getElementById('map').appendChild(locationButton); | ||
|
||
locationButton.addEventListener('click', () => { | ||
if (navigator.geolocation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistically, I prefer early returns over deep nesting. it makes it easier to read your code and follow the control flow. What I mean by this here is to flip your conditions around:
if (!navigator.geolocation) {
alert('Geolocation is not supported by this browser.');
return;
}
// ... continue on with the rest of your logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's a great approach. I have added the early return statement.
src/components/map/GoogleMap.svelte
Outdated
const userLocation = new google.maps.LatLng(latitude, longitude); | ||
map.setCenter(userLocation); | ||
|
||
new google.maps.Marker({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we want the button to be a reusable component, can you keep this marker logic here and invoke it with a callback from the LocationButton component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done this one.
src/components/map/GoogleMap.svelte
Outdated
@@ -104,6 +142,10 @@ | |||
}); | |||
</script> | |||
|
|||
<link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to remove this after making the other changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, great work! 👏
Fixed #4
Tasks done:
Screenshot: