Thuta Learning
AdvancedMobile Developmentintermediate

Working with Device Features (Camera, Location)

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Working with Device Features (Camera, Location) without the intimidation factor
  • Write the code yourself and run it on Expo Go
  • Apply this concept immediately in a real app project

Let's think about it this way for a second

Before accessing a device feature (camera, location, contacts), you need to request permission from the user (an iOS/Android OS-level requirement) — packages like expo-camera and expo-location provide a requestPermissionsAsync() function, and you have to handle the user's 'Allow'/'Deny' choice. If permission is denied, gracefully disable/explain the feature — the app must not crash.

Let's connect this to a real-world scenario

Install expo-location and call Location.requestForegroundPermissionsAsync(), and the OS's native permission dialog will appear — once you get 'Allow', you can fetch GPS coordinates with Location.getCurrentPositionAsync(). Always check the permission status (granted/denied), and if status !== 'granted', show a UI message explaining that the feature is limited.

Code Example

javascript
import * as Location from 'expo-location';
import { useState, useEffect } from 'react';
import { Text } from 'react-native';

function LocationScreen() {
  const [location, setLocation] = useState(null);
  const [errorMsg, setErrorMsg] = useState(null);

  useEffect(() => {
    (async () => {
      const { status } = await Location.requestForegroundPermissionsAsync();
      if (status !== 'granted') {
        setErrorMsg('Location permission ကို ငြင်းပယ်ထားပါတယ်');
        return;
      }
      const loc = await Location.getCurrentPositionAsync({});
      setLocation(loc);
    })();
  }, []);

  if (errorMsg) return <Text>{errorMsg}</Text>;
  return <Text>{location ? JSON.stringify(location.coords) : 'Loading...'}</Text>;
}
You should see
A permission dialog appears, and tapping 'Allow' displays the device's GPS coordinates on screen.

Try it in 5 minutes

Install expo-location and implement the permission request + current location fetch flow yourself (on the Expo Go app).

A quick word of caution

Location/camera data is sensitive personal information — clearly explain to the user why it's needed before requesting permission, and if you send it to a backend, follow the encryption/HTTPS concepts from the Cybersecurity tutorial.

Easy traps

  • Calling getCurrentPositionAsync() right away without checking permission status first, and crashing when it's denied
  • Requesting camera/location permission the moment the app opens (with no clear context) — this makes users suspicious

Now try it yourself

Install expo-location and implement the permission request + current location fetch flow yourself (on the Expo Go app).

You'll know it worked when: A permission dialog appears, and tapping 'Allow' displays the device's GPS coordinates on screen.

Working with Device Features (Camera, Location) | Thuta Learning