GPS location and permission handling for NativePHP Mobile applications.
# Install the package
composer require nativephp/geolocation
# Publish the plugins provider (first time only)
php artisan vendor:publish --tag=nativephp-plugins-provider
# Register the plugin
php artisan native:plugin:register nativephp/geolocation
# Verify registration
php artisan native:plugin:listThis adds \NativePHP\Geolocation\GeolocationServiceProvider::class to your plugins() array.
use NativePHP\Geolocation\Facades\Geolocation;
// Get current position with high accuracy
Geolocation::getCurrentPosition()
->fineAccuracy()
->id('my-location-request')
->get();
// Check permission status
Geolocation::checkPermissions()->get();
// Request permissions
Geolocation::requestPermissions()->get();use Livewire\Component;
use Native\Mobile\Attributes\OnNative;
use NativePHP\Geolocation\Events\LocationReceived;
class LocationTracker extends Component
{
public ?float $latitude = null;
public ?float $longitude = null;
#[OnNative(LocationReceived::class)]
public function handleLocation(
bool $success,
?float $latitude,
?float $longitude,
?float $accuracy,
?int $timestamp,
?string $provider,
?string $error,
?string $id
) {
if ($success) {
$this->latitude = $latitude;
$this->longitude = $longitude;
}
}
}| Event | Description |
|---|---|
LocationReceived |
Fired when location is received |
PermissionStatusReceived |
Fired when permission check completes |
PermissionRequestResult |
Fired when permission request completes |
android.permission.ACCESS_FINE_LOCATIONandroid.permission.ACCESS_COARSE_LOCATION
NSLocationWhenInUseUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescription
MIT