搜索插件、代码仓与 APP 分类

location 封面
插件详情v10.2.0

location

跨平台插件,可轻松实时访问设备位置。

AndroidiOSWebmacOS
近 30 天下载
22.6万
喜欢数
3210
Pub 分数
150

安装插件

flutter pub add location

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

location 包为 Android、iOS、Web 和 macOS 提供了跨平台的实时设备位置访问解决方案。它通过跨平台一致的 API 简化了地理定位任务,使开发者能够轻松获取当前位置、监控位置变化并无缝处理权限。该包设计简洁易用,抽象了平台特定的复杂性,同时保持了可靠性和性能。非常适合需要基于位置服务的应用程序,例如地图、跟踪或接近功能。

适合场景

  • 实时位置跟踪
  • 地理围栏集成
  • 基于地图的应用程序
  • 用户位置检索
  • 位置感知通知
  • 旅行和导航应用

主要特点

  • 跨平台兼容性
  • 实时位置更新
  • 权限处理
  • 简单API接口
  • 支持所有主要平台
  • 后台位置访问

适合对象

  • 移动应用开发者
  • 基于位置的服务应用
  • 跟踪和映射工具
  • 网页和桌面位置应用
  • 需要精确设备定位的应用程序

使用建议

  • 需要正确的权限配置
  • 后台位置信息可能影响电池续航
  • Web 支持仅限浏览器地理位置
  • iOS 要求在 info.plist 中包含隐私说明
  • Android 需要在清单文件中具有位置权限
  • 准确性取决于设备硬件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

📍 Flutter Location

The easiest way to get a device's location in real-time — on every platform Flutter runs.

One simple API for GPS coordinates, live location streams and background tracking on Android, iOS, macOS, Web, Windows and Linux.

pub version pub likes pub points codecov license

📖 Documentation  ·  🌐 Live web demo  ·  📦 pub.dev  ·  💬 Feedback


✨ Why Location?

  • 🌍 Truly cross-platform — the same code runs on all six Flutter targets, no per-platform branching.
  • ⚡ One-line to a fix — await location.getLocation() and you're done.
  • 🔴 Real-time streams — subscribe to onLocationChanged for continuous updates.
  • 🌙 Background tracking — keep receiving locations while your app is backgrounded on Android & iOS.
  • 🎛️ Tunable — pick accuracy, update interval and distance filter to balance precision vs. battery.
  • 🔔 Customizable notification — full control over the Android foreground-service notification.
  • 📊 Rich data — latitude, longitude, altitude, speed, heading, accuracy, mock detection and more.
  • 🛡️ Battle-tested — one of the most-used location plugins in the Flutter ecosystem, maintained since 2017.

📱 Platform support

Feature Android iOS macOS Web Windows Linux
One-time location ✅ ✅ ✅ ✅ ✅ ✅
Location stream ✅ ✅ ✅ ✅ ✅ ✅
Background updates ✅ ✅ — — — —
Permission handling ✅ ✅ ✅ ✅ ✅ ✅

Windows uses Windows.Devices.Geolocation; Linux talks to GeoClue2 over D-Bus. Both require the system location service to be enabled.

Watch the demo on YouTube

🚀 Quick start

Add the package:

dependencies:
  location: ^10.0.0

Get a location:

import 'package:location/location.dart';

final location = Location();

// Make sure the service is on and permission is granted.
if (!await location.serviceEnabled() && !await location.requestService()) return;
if (await location.requestPermission() != PermissionStatus.granted) return;

// One-time fix…
final current = await location.getLocation();
print('${current.latitude}, ${current.longitude}');

// …or a live stream.
location.onLocationChanged.listen((loc) {
  print('Moved to ${loc.latitude}, ${loc.longitude}');
});

That's it. Platform setup (permissions, background mode, sandbox entitlements) and the full API are covered in the package README and the documentation website.

📦 Packages in this repository

Package Description pub.dev
location The plugin you use in your app. pub
location_platform_interface Shared platform interface. pub
location_web Web implementation. pub

🤝 Contributing

Issues and pull requests are very welcome — this plugin is community-maintained and we're always looking for help. Browse the open issues to get started, or open a new one to report a bug or request a feature.

👥 Maintainers

📄 License

Released under the MIT License. © 2017 Guillaume Bernos.

所属分类

依赖

依赖清单 2 项

  • location_platform_interface^7.0.0
  • location_web^7.0.0

源码仓库

使用此插件的项目

所在榜单