flutter_osm_plugin 0.3.6+4

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

flutter_osm_plugin #

pub

osm plugin for flutter apps (only Android for now, iOS will be supported in future)

  • current position
  • change position
  • tracking user location
  • customize Icon Marker
  • draw Road
  • ClickListener on Marker

Getting Started #

Installing #

Add the following to your pubspec.yaml file:

dependencies:
  flutter_osm_plugin: ^0.3.6+4

Simple Usage #

Creating a basic OSMFlutter:

OSMFlutter( 
    key: osmKey,
    currentLocation: false,
    road: Road(
            startIcon: MarkerIcon(
              icon: Icon(
                Icons.person,
                size: 64,
                color: Colors.brown,
              ),
            ),
            roadColor: Colors.yellowAccent,
    ),
    markerIcon: MarkerIcon(
    icon: Icon(
      Icons.person_pin_circle,
      color: Colors.blue,
      size: 56,
      ),
    ),
    initPosition: GeoPoint(latitude: 47.35387, longitude: 8.43609),
);

Declare GlobalKey #

GlobalKey<OSMFlutterState> osmKey = GlobalKey<OSMFlutterState>();

set map on user current position #

osmKey.currentState.currentPosition()

zoomIN #

osmKey.currentState.zoom(2.)

zoomOut #

osmKey.currentState.zoom(-2.)

track user current position or disable tracking #

osmKey.currentState.enableTracking()

initialise position #

osmKey.currentState.changeLocation(GeoPoint(latitude: 47.35387, longitude: 8.43609))

recuperation current position #

GeoPoint geoPoint = osmKey.currentState.myLocation()

select/create new position #

GeoPoint geoPoint = osmKey.currentState.selectPosition()

draw road #

osmKey.currentState.drawRoad( GeoPoint(latitude: 47.35387, longitude: 8.43609),GeoPoint(latitude: 47.4371, longitude: 8.6136));

change static geopoint position #

you can use it if you don't have at first static position and you need to add staticPoints with empty list of geoPoints you can use it to change their position over time osmKey.currentState.setStaticPosition(List<GeoPoint> geoPoints,String id )

OSMFlutter

PropertiesDescription
currentLocationenable the current position.
trackMyPositionenbaled tracking user position.
showZoomControllershow default zoom controller.
initPositionset default position showing in map
markerIconset icon Marker
roadset color and start/end/middle markers in road
useSecureURLenabled secure urls
staticPointsList of Markers you want to show always ,should every marker have unique id
onGeoPointClickedlistener on static geoPoint

NOTICE: #

for now the map working only for android,iOS will be available soon

if you get ssl certfiction exception,use can use http by following instruction below

if you want to use http in Android PIE or above :

  • enable useSecureURL and add android:usesCleartextTraffic="true" in your manifest like example below :

    • <application ... android:usesCleartextTraffic="true">

MIT LICENCE

0.3.6+4 [beta-version]: #

  • request permission only when you want to activate tracking or get current location

0.3.6+3 [beta-version]: #

  • upgrade dependencies

0.3.6+2 [beta-version]: #

  • change longPress in selectPosition to simplePress
  • fix error and behavior

0.3.6+1 [beta-version]: #

  • fix draw last point in draw

0.3.6 [beta-version]: #

  • staticPoints become list of Markers with unique id
  • add callback setStaticPosition to set position if you don't have it or to change it over time
  • to use setStaticPosition correctly you need to initialize staticPoints with markers that have empty geoPoints and unique ids

0.3.5+1 [beta-version]: #

  • fix problem show address when geoPoint clicked

0.3.5 [beta-version]: new feature #

  • add static geoPoint
  • listener click for static geoPoint
  • fix error
  • improve more code

0.3.4 [alpha-version]: customisation infowindow of marker #

*show adresse from geopoint

0.3.3 [alpha-version]: #

  • widget road to modify marker in road and color of line
  • enable/disable https to get road in map

0.3.2+1 [alpha-version]: #

  • fix readme

0.3.2 [alpha-version]: #

  • draw road
  • handle geopoint and road exception

0.3.0 [alpha-version]: #

  • pick position and recuperation of the position

0.2.0 [alpha-version]: #

  • Custom Marker Icon

0.1.1 [alpha-version]: #

  • you can now ,recuperation your current location

0.1.0+4 [alpha-version]: #

  • fix readme

0.1.0+3 [alpha-version]: #

  • fix zoom parametre

0.1.0+2 [alpha-version]: #

  • fix readme

0.1.0+1 [alpha-version]: #

0.1.0 [alpha-version]: #

  • contain basic for android
  • trakcing,set position,current position

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

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

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  GlobalKey<OSMFlutterState> osmKey;
  GlobalKey<ScaffoldState> scaffoldKey;

  @override
  void initState() {
    super.initState();
    osmKey = GlobalKey<OSMFlutterState>();
    scaffoldKey = GlobalKey<ScaffoldState>();
  }
  @override
  Widget build(BuildContext loncontext) {
    return MaterialApp(
      home: Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: const Text('OSM Plugin app'),
          actions: <Widget>[
            IconButton(
              onPressed: () async {
                try {
                  ///selection geoPoint
                  GeoPoint point=await osmKey.currentState.selectPosition();
                  GeoPoint point2=await osmKey.currentState.selectPosition();
                  await osmKey.currentState.drawRoad(
                      point,
                      point2);
                } on RoadException catch (e) {
                  scaffoldKey.currentState.showSnackBar(
                    SnackBar(
                      content: Text(
                        "${e.errorMessage()}",
                      ),
                    ),
                  );
                }
              },
              icon: Icon(Icons.map),
            ),
            IconButton(
              onPressed: () async {
                GeoPoint p = await osmKey.currentState.selectPosition();
                scaffoldKey.currentState.showSnackBar(
                  SnackBar(
                    content: Text(
                      "the picked position:lat ${p.latitude},lon ${p.longitude}",
                    ),
                  ),
                );
              },
              icon: Icon(Icons.search),
            ),
            IconButton(
              icon: Icon(Icons.refresh),
              onPressed: () async {
                await osmKey.currentState.setStaticPosition([
                  GeoPoint(latitude: 47.434541, longitude: 8.467369),
                  GeoPoint(latitude: 47.436207, longitude: 8.464072),
                  GeoPoint(latitude: 47.437688, longitude: 8.460832),
                ], "static");
                scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text("static point changed"),
                  duration: Duration(seconds: 10),
                ));
              },
            )
          ],
        ),
        body: Container(
          child: OSMFlutter(
            key: osmKey,
            currentLocation: false,
            onGeoPointClicked: (geoPoint) {
              scaffoldKey.currentState.showSnackBar(
                SnackBar(
                  content: Text(
                    "lat:${geoPoint.latitude},lon${geoPoint.longitude}",
                  ),
                  action: SnackBarAction(
                    onPressed: () =>
                        scaffoldKey.currentState.hideCurrentSnackBar(),
                    label: "hide",
                  ),
                ),
              );
            },
            staticPoints: [
              StaticPositionGeoPoint(
                "static",
                MarkerIcon(
                  icon: Icon(
                    Icons.train,
                    color: Colors.green,
                    size: 48,
                  ),
                ),
                [
                  GeoPoint(latitude: 47.4333594, longitude: 8.4680184),
                  GeoPoint(latitude: 47.4317782, longitude: 8.4716146),
                ],
              ),
            ],
            road: Road(
                startIcon: MarkerIcon(
                  icon: Icon(
                    Icons.person,
                    size: 64,
                    color: Colors.brown,
                  ),
                ),
                roadColor: Colors.yellowAccent),
            markerIcon: MarkerIcon(
              icon: Icon(
                Icons.person_pin_circle,
                color: Colors.blue,
                size: 56,
              ),
            ),
            trackMyPosition: false,
            initPosition: GeoPoint(latitude: 47.4358055, longitude: 8.4737324),
            useSecureURL: false,
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            await osmKey.currentState.currentLocation();
            await osmKey.currentState.enableTracking();
          },
          child: Icon(Icons.my_location),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_osm_plugin: ^0.3.6+4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_osm_plugin/flutter_osm_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_osm_plugin/flutter_osm_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_osm_plugin/flutter_osm_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_osm_plugin/flutter_osm_plugin.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_osm_plugin that is a package requiring null.

Health suggestions

Format lib/src/geo_point.dart.

Run flutter format to format lib/src/geo_point.dart.

Format lib/src/geo_static.dart.

Run flutter format to format lib/src/geo_static.dart.

Format lib/src/osm_flutter.dart.

Run flutter format to format lib/src/osm_flutter.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
after_layout ^1.0.7+2 1.0.7+2
flutter 0.0.0
flutter_plugin_android_lifecycle ^1.0.8 1.0.8
location_permissions ^3.0.0 3.0.0+1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test