maui-geolocation

Retrieve device location with timeouts, permissions, and fallbacks in .NET MAUI apps.

Updated Nov 27, 2025
One-click install
npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-geolocation-seydakaratekeli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-geolocation
Source: https://github.com/seydakaratekeli/KamPay3/tree/main/KamPay/.github/skills/maui-geolocation%20-%20Kopyala
Command: npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-geolocation-seydakaratekeli

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provide reliable device location retrieval for .NET MAUI apps while avoiding hangs, excessive battery drain, and inconsistent platform behavior caused by missing timeouts, improper accuracy settings, or unhandled permission flows.

Core Features & Use Cases

  • Cancellation and timeouts to prevent GetLocationAsync from hanging when GPS is unavailable or indoors.
  • Accuracy vs. battery guidance to choose Lowest/Low/Medium/High/Best based on feature needs.
  • One-shot and continuous location patterns with StartListening/StopListening and proper event unsubscription.
  • Platform-specific permission and manifest guidance for Android, iOS, macOS, and Windows, including background location and iOS full-accuracy prompts.
  • Security checks and fallbacks such as mock-location detection, treating Altitude 0.0 as unknown, and caching with GetLastKnownLocationAsync fallback.
  • DI-friendly wrapper example to register IGeolocation and provide a GetCurrentAsync with sensible fallbacks.

Quick Start

Ask for a sample .NET MAUI method that fetches the current location with a CancellationToken timeout, requests runtime permissions, falls back to the last-known location if recent, and rejects mock-provider locations.

Frequently Asked Questions about maui-geolocation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop .NET MAUI GetLocationAsync from hanging when GPS is unavailable?

Use a CancellationToken with GetLocationAsync to prevent hangs when GPS is unavailable or indoors. This enforces a timeout, allowing the app to fall back to GetLastKnownLocationAsync instead of waiting indefinitely for a fix.

What GPS accuracy level should I use in .NET MAUI to balance battery drain?

To balance battery drain in .NET MAUI, select accuracy levels based on feature needs: use Lowest or Low for coarse tracking, Medium for standard navigation, and High or Best only for precise positioning. Higher accuracy consumes significantly more battery power.

How do I configure location permissions for .NET MAUI on Android and iOS?

Configuring location permissions for .NET MAUI requires adding platform-specific manifest entries on Android and info.plist keys on iOS. Runtime permission prompts must be requested in code, with iOS requiring full-accuracy prompts and Android handling background access nuances.

Can I detect mock locations or fake GPS in a .NET MAUI app?

Yes, you can detect mock locations in a .NET MAUI app by checking location provider flags. Reject spoofed coordinates by validating provider flags and treating Altitude 0.0 as unknown to filter potentially invalid mock-provider locations.

Does .NET MAUI support continuous background location tracking?

.NET MAUI supports continuous location tracking using StartListening and StopListening with proper event unsubscription. Background location access requires platform-specific manifest permissions and configuration on Android and iOS to sustain updates while the app is backgrounded.

What is the best way to register geolocation services for dependency injection in .NET MAUI?

The best way to register geolocation services for dependency injection in .NET MAUI is wrapping IGeolocation in a DI-friendly service. This provides a GetCurrentAsync method with sensible fallbacks like GetLastKnownLocationAsync for cleaner architecture.