Maroon-Rides/MaroonRides

Add button to recenter map on user's location

Closed this issue · 9 comments

Add a button ontop of the map view to recenter the map on the current location of the user.

Currently, we do not have anything that would recenter the map:
Screenshot 2023-10-23 at 1 20 54 AM

Some sort of icon with styling to recenter the map would look something like this:
Screenshot 2023-10-23 at 1 22 22 AM

You can extract the functionality out of the useEffect block into a separate function, but make sure to call it in the useEffect function as well:

useEffect(() => {
        (async () => {
            let { status } = await Location.requestForegroundPermissionsAsync();
            if (status !== 'granted') {
                return;
            }

            let location = await Location.getCurrentPositionAsync({
                accuracy: Location.Accuracy.Balanced,
                timeInterval: 2
            });

            setLocation({ latitude: location.coords.latitude, longitude: location.coords.longitude, latitudeDelta: 0.019075511625736397, longitudeDelta: 0.011273115836317515 });
        })();
    }, []);

This code requests permission to use the users location while the app is open and if it is granted, sets the latitude and longitude in a state variable.

The latitude/longitude are then passed into a MapView component in the region attribute as such:

 <StyledMapView 
            showsUserLocation={true}
            region={location}
            className='w-full h-full' />

Please leave a comment saying you want to be assigned to the issue and open a pull request for code review!

bwees commented

I will do this!

I will do this!

Go for it!

bwees commented

How do you want me to handle icons? I was gonna add one to recenter like the iOS one.

I can add the react native vector icons library in this pr if you would like

react native vector icons

Sounds good, we'll probably need an icon library in the future anyway

bwees commented

See #8

bwees commented

image

bwees commented

I dont think there is a reason to show a profile icon since we are not going to have a server component at this time and it is also a similar UI to other map apps.

I dont think there is a reason to show a profile icon since we are not going to have a server component at this time and it is also a similar UI to other map apps.

I agree I like what you have right now. Give me some time I'll do a code review.

Completed in #8