Skip to content

NativePHP/Geolocation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geolocation Plugin for NativePHP Mobile

GPS location and permission handling for NativePHP Mobile applications.

Installation

# 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:list

This adds \NativePHP\Geolocation\GeolocationServiceProvider::class to your plugins() array.

Usage

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();

Listening for Events

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;
        }
    }
}

Events

Event Description
LocationReceived Fired when location is received
PermissionStatusReceived Fired when permission check completes
PermissionRequestResult Fired when permission request completes

Permissions

Android

  • android.permission.ACCESS_FINE_LOCATION
  • android.permission.ACCESS_COARSE_LOCATION

iOS

  • NSLocationWhenInUseUsageDescription
  • NSLocationAlwaysAndWhenInUseUsageDescription

License

MIT