@@ -164,142 +164,6 @@ public function handlePermissionRequest($location, $coarseLocation, $fineLocatio
164
164
}
165
165
```
166
166
167
- ## Complete Example
168
-
169
- ``` php
170
- use Livewire\Component;
171
- use Livewire\Attributes\On;
172
- use Native\Mobile\Facades\Geolocation;
173
- use Native\Mobile\Events\Geolocation\LocationReceived;
174
- use Native\Mobile\Events\Geolocation\PermissionStatusReceived;
175
- use Native\Mobile\Events\Geolocation\PermissionRequestResult;
176
-
177
- class LocationTracker extends Component
178
- {
179
- public ?float $latitude = null;
180
- public ?float $longitude = null;
181
- public ?float $accuracy = null;
182
- public ?string $provider = null;
183
- public bool $isLoading = false;
184
- public string $error = '';
185
- public bool $showSettingsPrompt = false;
186
-
187
- // Permission states
188
- public string $locationPermission = 'unknown';
189
- public string $coarsePermission = 'unknown';
190
- public string $finePermission = 'unknown';
191
-
192
- public function mount()
193
- {
194
- // Check current permissions on load
195
- $this->checkPermissions();
196
- }
197
-
198
- public function checkPermissions()
199
- {
200
- $this->error = '';
201
- Geolocation::checkPermissions();
202
- }
203
-
204
- public function requestPermissions()
205
- {
206
- $this->error = '';
207
- $this->isLoading = true;
208
- Geolocation::requestPermissions();
209
- }
210
-
211
- public function getCurrentLocation()
212
- {
213
- $this->isLoading = true;
214
- $this->error = '';
215
-
216
- // Use high accuracy GPS
217
- Geolocation::getCurrentPosition(true);
218
- }
219
-
220
- #[On('native:' . PermissionStatusReceived::class)]
221
- public function handlePermissionStatus($location, $coarseLocation, $fineLocation)
222
- {
223
- $this->locationPermission = $location;
224
- $this->coarsePermission = $coarseLocation;
225
- $this->finePermission = $fineLocation;
226
-
227
- if ($coarseLocation === 'granted' || $fineLocation === 'granted') {
228
- // Has some level of location permission
229
- $this->showLocationButton = true;
230
- } elseif ($location === 'denied') {
231
- // Permission denied - can request again
232
- $this->showRequestButton = true;
233
- } else {
234
- // Permission not determined - can request
235
- $this->showRequestButton = true;
236
- }
237
- }
238
-
239
- #[On('native:' . PermissionRequestResult::class)]
240
- public function handlePermissionRequest($location, $coarseLocation, $fineLocation, $message = null, $needsSettings = null)
241
- {
242
- $this->isLoading = false;
243
-
244
- if ($location === 'permanently_denied') {
245
- $this->error = $message ?? 'Location access permanently denied. Please enable location services in your device Settings app.';
246
- $this->showSettingsPrompt = true;
247
- } elseif ($coarseLocation === 'granted' || $fineLocation === 'granted') {
248
- // Permission granted - automatically get location
249
- $this->getCurrentLocation();
250
- } else {
251
- $this->error = 'Location permission is required to use this feature.';
252
- }
253
- }
254
-
255
- #[On('native:' . LocationReceived::class)]
256
- public function handleLocationReceived($success = null, $latitude = null, $longitude = null, $accuracy = null, $timestamp = null, $provider = null, $error = null)
257
- {
258
- $this->isLoading = false;
259
-
260
- if ($success) {
261
- $this->latitude = $latitude;
262
- $this->longitude = $longitude;
263
- $this->accuracy = $accuracy;
264
- $this->provider = $provider;
265
- $this->error = '';
266
-
267
- // Store for later use
268
- session([
269
- 'last_location' => [
270
- 'lat' => $latitude,
271
- 'lng' => $longitude,
272
- 'accuracy' => $accuracy,
273
- 'timestamp' => $timestamp,
274
- 'provider' => $provider
275
- ]
276
- ]);
277
-
278
- Log::info('Location updated', [
279
- 'lat' => $latitude,
280
- 'lng' => $longitude,
281
- 'accuracy' => $accuracy
282
- ]);
283
-
284
- } else {
285
- $this->error = $error ?? 'Failed to get current location';
286
- Log::warning('Location request failed', ['error' => $error]);
287
- }
288
- }
289
-
290
- public function openSettings()
291
- {
292
- // You might want to show instructions or deep link to settings
293
- $this->dispatch('show-settings-instructions');
294
- }
295
-
296
- public function render()
297
- {
298
- return view('livewire.location-tracker');
299
- }
300
- }
301
- ```
302
-
303
167
## Understanding Permission States
304
168
305
169
### Permission Types
@@ -316,45 +180,6 @@ class LocationTracker extends Component
316
180
- More battery usage
317
181
- Slower initial location fix
318
182
319
- ### Permission Flow
320
-
321
- ``` php
322
- class PermissionFlowExample extends Component
323
- {
324
- public function handleLocationFlow()
325
- {
326
- // 1. Check current permissions
327
- Geolocation::checkPermissions();
328
- }
329
-
330
- #[On('native:' . PermissionStatusReceived::class)]
331
- public function handleCheck($location, $coarseLocation, $fineLocation)
332
- {
333
- if ($coarseLocation === 'granted' || $fineLocation === 'granted') {
334
- // 2a. Permission already granted - get location
335
- Geolocation::getCurrentPosition(true);
336
- } else {
337
- // 2b. Need to request permission
338
- Geolocation::requestPermissions();
339
- }
340
- }
341
-
342
- #[On('native:' . PermissionRequestResult::class)]
343
- public function handleRequest($location, $coarseLocation, $fineLocation, $message = null, $needsSettings = null)
344
- {
345
- if ($location === 'permanently_denied') {
346
- // 3a. User must enable in Settings
347
- $this->showSettingsInstructions($message);
348
- } elseif ($coarseLocation === 'granted' || $fineLocation === 'granted') {
349
- // 3b. Permission granted - get location
350
- Geolocation::getCurrentPosition(true);
351
- } else {
352
- // 3c. Permission denied - show explanation
353
- $this->showPermissionExplanation();
354
- }
355
- }
356
- }
357
- ```
358
183
359
184
## Platform Support
360
185
@@ -379,38 +204,6 @@ class PermissionFlowExample extends Component
379
204
- ** Use appropriate accuracy** - don't request fine location if coarse is sufficient
380
205
- ** Limit frequency** - don't request location updates constantly
381
206
382
- ### User Experience Tips
383
-
384
- ``` php
385
- class LocationUX extends Component
386
- {
387
- public function requestLocationWithExplanation()
388
- {
389
- // Show explanation first
390
- $this->showExplanation = true;
391
- }
392
-
393
- public function proceedWithLocationRequest()
394
- {
395
- $this->showExplanation = false;
396
-
397
- // Now request permission
398
- Geolocation::requestPermissions();
399
- }
400
-
401
- public function handleDeniedGracefully($location, $coarseLocation, $fineLocation)
402
- {
403
- if ($location === 'permanently_denied') {
404
- // Offer manual location entry
405
- $this->showManualLocationEntry = true;
406
- } else {
407
- // Show benefit of enabling location
408
- $this->showLocationBenefits = true;
409
- }
410
- }
411
- }
412
- ```
413
-
414
207
## Accuracy and Performance
415
208
416
209
### Choosing Accuracy Level
0 commit comments