GeoPointer | Library for calculating latitude and longitude in Flutter

A lightweight flutter library for common latitude and longitude calculation..

Getting Started

GeoPointer 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!

Basic usage

GDistance

    final GDistance distance = new GDistance();

    //in km = 423
    final int km = distance.as(LengthUnit.Kilometer,
     new GeoLatLng(52.518611,13.408056),new GeoLatLng(51.519475,7.46694444));

    //in meter = 422591.551
    final int meter = distance(
        new GeoLatLng(52.518611,13.408056),
        new GeoLatLng(51.519475,7.46694444)
        );

Offset

    final GDistance distance = const GDistance();
    final num distanceInMeter = (EARTH_RADIUS * math.PI / 4).round();

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

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

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

GeoPath smoothing

    // coordinates is a list of coordinates
    final GeoPath path = new GeoPath.from(coordinates);

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

 

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add geopointer

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  geopointer: ^0.0.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:geopointer/geopointer.dart';

example/lib/main.dart
 

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:geopointer/geopointer.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await Geopointer.platformVersion ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}

Download Details:

Official Website: https://pub.dev/packages/geopointer 

11.45 GEEK