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

latlong2 封面
插件详情v0.10.1

latlong2

用于常见纬度和经度计算的轻量级库

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
139万
喜欢数
403
Pub 分数
150

安装插件

flutter pub add latlong2

插件介绍

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

latlong2 是一个轻量级的 Dart 库,专为高效且精确的纬度和经度计算而设计。它提供了基本的地理空间工具,例如距离计算、中点确定和坐标转换。该库注重性能和简洁性,支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台。对于需要基础地理位置操作但又不想使用大型地图框架开销的应用程序来说,这是一个理想选择。其清晰的 API 使其易于集成到 Flutter 项目中。

适合场景

  • 计算两个坐标之间的距离
  • 查找位置之间的中点
  • 在坐标格式之间转换
  • 地理围栏和近距离检测
  • 基于地图的应用开发

主要特点

  • 轻量且快速
  • 跨平台支持
  • 简单直观的 API
  • 支持常见的地理空间操作
  • 无外部依赖

适合对象

  • 需要地理定位计算的 Flutter 应用
  • 开发地图功能的开发者
  • 需要最少地理空间逻辑的项目
  • 原型设计基于位置的服务
  • 面向多个平台的应用程序

使用建议

  • 不包括完整的地图渲染
  • 仅限基本地理空间计算
  • 无内置地理编码或反向地理编码
  • 不适合复杂的GIS任务
  • 需要手动处理极点等边缘情况

原始 README

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

This is a fork of https://github.com/MikeMitterer/dart-latlong. The goal is to keep it up to date with Dart language changes.

LatLong provides a lightweight library for common latitude and longitude calculation.

This library supports both, the "Haversine" and the "Vincenty" algorithm.

"Haversine" is a bit faster but "Vincenty" is far more accurate!

LatLong

Catmull-Rom algorithm is used for smoothing out the path.

Basic usage

Distance
final Distance distance = Distance();

// km = 423
final double km = distance.as(LengthUnit.kilometer,
    LatLng(52.518611, 13.408056), LatLng(51.519475, 7.46694444));

// meter = 422591.551
final double meter = distance(
  LatLng(52.518611, 13.408056),
  LatLng(51.519475, 7.46694444),
);

Offset

final Distance distance = const Distance();
final num distanceInMeter = (earthRadius * pi / 4).round();

final p1 = LatLng(0.0, 0.0);
final p2 = distance.offset(p1, distanceInMeter, 180);

// LatLng(latitude:-45.219848, longitude:0.0)
print(p2.round());

// 45° 13' 11.45" S, 0° 0' 0.00" O
print(p2.toSexagesimal());

Path smoothing

// zigzag is a list of coordinates
final Path path = Path.from(zigzag);

// Result is below
final Path steps = path.equalize(8, smoothPath: true);

Smooth path

Features and bugs

Please file feature requests and bugs at the issue tracker.

License

Copyright 2015 Michael Mitterer (office@mikemitterer.at),
IT-Consulting and Development Limited, Austrian Branch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language
governing permissions and limitations under the License.

If this plugin is helpful for you - please (Circle) me or star this repo here on GitHub

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目