Location changes everything. Delivery apps need addresses. Fitness apps track runs. Social apps find nearby friends.
With NativePHP, you get real GPS coordinates — not browser geolocation that may or may not work.
In this post:
#Getting the Current Location
#PHP (Livewire)
Copied!
use Native\Mobile\Facades\Geolocation;use Native\Mobile\Events\Geolocation\LocationReceived; public function getLocation(){ Geolocation::getCurrentPosition()->fineAccuracy(true)->id('current');} #[On('native:' . LocationReceived::class)]public function handleLocation(float $latitude, float $longitude, float $accuracy, string $id){ $this->latitude = $latitude; $this->longitude = $longitude;}
#JavaScript (Vue/React/Inertia)
Copied!
import { Geolocation, On, Off, Events } from '@nativephp/mobile'; const getLocation = async () => { await Geolocation.getCurrentPosition().fineAccuracy(true).id('current');}; On(Events.Geolocation.LocationReceived, ({ latitude, longitude, accuracy, id }) => { position.value = { latitude, longitude };});
#Handling Permissions
#PHP (Livewire)
Copied!
use Native\Mobile\Events\Geolocation\PermissionStatusReceived; Geolocation::checkPermissions()->id('check'); #[On('native:' . PermissionStatusReceived::class)]public function handleStatus(string $status, string $id){ match ($status) { 'granted' => $this->fetchLocation(), 'prompt' => Geolocation::requestPermissions(), default => $this->showDeniedMessage(), };}
#JavaScript (Vue/React/Inertia)
Copied!
import { Geolocation, On, Off, Events } from '@nativephp/mobile'; await Geolocation.checkPermissions().id('check'); On(Events.Geolocation.PermissionStatusReceived, ({ status }) => { if (status === 'granted') { fetchLocation(); } else if (status === 'prompt') { Geolocation.requestPermissions(); } else { showDeniedMessage(); }});
#Accuracy Levels
#Fine Accuracy (GPS)
Copied!
Geolocation::getCurrentPosition()->fineAccuracy(true);
- Uses GPS hardware
- Accuracy: 5-20 meters
- Best for: Navigation, fitness tracking
#Coarse Accuracy (Network)
Copied!
Geolocation::getCurrentPosition(); // Default
- Uses WiFi/cell towers
- Accuracy: 100-500 meters
- Best for: City-level location
#Privacy Best Practices
- Ask only when needed — Not on app launch
- Explain why — Tell users what you'll do with their location
- Use minimum accuracy — If city-level is enough, don't request GPS
- Don't store what you don't need — City names, not coordinates
Your app now knows where your users are. Use that power responsibly.
Happy mapping! 📍