Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter_osm_plugin

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
  • assisted selection position
  • draw road,recuperate information (duration/distance) of the current road
  • clicklistener on marker
  • calculate distance between 2 points
  • address suggestion
  • draw shapes
  • simple dialog location picker

getting started

osm

searchexample

dialogsimplepickerlocation

installing

add the following to your pubspec.yaml file:

dependencies:
  flutter_osm_plugin: ^0.7.5

simple usage

creating a basic osmflutter :

 osmflutter( 
        controler:mapcontroller,
        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),
    );

mapcontroller

declare mapcontroller to control osm map

1) initialisation

 mapcontroller controller = mapcontroller(
                            initmapwithuserposition: false,
                            initposition: geopoint(latitude: 47.4358055, longitude: 8.4737324),
                       );

2) dispose

     controller.dispose();

3) properties of mapcontroller

properties description
initmapwithuserposition (bool) initialize map with user position (default:true
initposition (geopoint) if it isn’t null, the map will be pointed at this position

4) set map on user current position

 await controller.currentposition();

5) zoom in

 await controller.zoom(2.);
 // or 
 await controller.zoomin();

6) zoom out

 await controller.zoom(-2.);
 // or 
 await controller.zoomout();

7) track user current position

 await controller.enabletracking();

8) disable tracking user position

 await controller.disabledtracking();

9) update the location

this method will create marker on that specific position

 await controller.changelocation(geopoint(latitude: 47.35387, longitude: 8.43609));

change the location without create marker

 await controller.gotolocation(geopoint(latitude: 47.35387, longitude: 8.43609));

10) recuperation current position

 geopoint geopoint = await controller.mylocation();

11) select/create new position

  • we have 2 way to select location in map

11.1 manual selection

 geopoint geopoint = await controller.selectposition();

11.2 assisted selection (for more details see example)

 /// to start assisted selection
 await controller.advancedpositionpicker();
 /// to get location desired
  geopoint p = await controller.getcurrentpositionadvancedpositionpicker();
  /// to get location desired and close picker
 geopoint p = await controller.selectadvancedpositionpicker();
 /// to cancel assisted selection
 await controller.canceladvancedpositionpicker();
  • ps : selected position can be removed by long press

12) remove marker

 await controller.removeposition(geopoint);
  • ps : static position cannot be removed by this method

13) draw road,recuperate distance in km and duration in sec

 roadinfo roadinfo = await controller.drawroad( 
   geopoint(latitude: 47.35387, longitude: 8.43609),
   geopoint(latitude: 47.4371, longitude: 8.6136),
   roadcolor : colors.green,
   roadwidth : 7.0,
);
 print("${roadinfo.distance}km");
 print("${roadinfo.duration}sec");

14) delete last road

 await controller.removelastroad();

15) 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

 await controller.setstaticposition(list<geopoint> geopoints,string id );

16) change orientation of the map

 await controller.rotatemapcamera(degree);

17) draw shape in the map

  • circle
 /// to draw
 await controller.drawcircle(circleosm(
              key: "circle0",
              centerpoint: geopoint(latitude: 47.4333594, longitude: 8.4680184),
              radius: 1200.0,
              color: colors.red,
              strokewidth: 0.3,
            ));
 /// to remove circle using key
 await controller.removecircle("circle0");

 /// to remove all circle in the map 
 await controller.removeallcircle();

  • rect
 /// to draw
 await controller.drawrect(rectosm(
              key: "rect",
              centerpoint: geopoint(latitude: 47.4333594, longitude: 8.4680184),
              distance: 1200.0,
              color: colors.red,
              strokewidth: 0.3,
            ));
 /// to remove rect using key
 await controller.removerect("rect");

 /// to remove all rect in the map 
 await controller.removeallrect();

  • remove all shapes in the map
 await controller.removeallshapes();

osmflutter

properties description
trackmyposition enbaled tracking user position.
showzoomcontroller show default zoom controller.
markericon set icon marker
defaultzoom set default zoom to use in zoomin()/zoomout() (default 1)
road set color and start/end/middle markers in road
usesecureurl enabled secure urls
staticpoints list of markers you want to show always ,should every marker have unique id
ongeopointclicked (callback) listener triggered when marker is clicked ,return current geopoint of the marker
onlocationchanged (callback) it is hire when you activate tracking and user position has been changed
showdefaultinfowindow (bool) enable/disable default infowindow of marker (default = false)
ispicker (bool) enable advanced picker from init of the map (default = false)

static methods:

1) calculate distance between 2 geopoint position

 double distanceenmetres = await distance2point(geopoint(longitude: 36.84612143139903,latitude: 11.099388684927824,),
        geopoint( longitude: 36.8388023164018, latitude: 11.096959785428027, ),);

2) get search suggestion of text

you should know that i’m using public api, don’t make lot of request

    list<searchinfo> suggestions = await addresssuggestion("address");

show dialog picker

simple dialog location picker to selected user location

geopoint p = await showsimplepickerlocation(
                      context: context,
                      isdismissible: true,
                      title: "title dialog",
                      textconfirmpicker: "pick",
                      initcurrentuserposition: true,
                    )

customlocationpicker

customizable widget to build search location

you should use pickermapcontroller as controller for the widget
see example : search widget

properties of customlocationpicker

properties description
controller (pickermapcontroller) controller of the widget
appbarpicker (appbar) appbar for the widget
topwidgetpicker (widget?) widget will be show on top of osm map,for example to show address suggestion
bottomwidgetpicker (widget?) widget will be show at bottom of screen for example to show more details about selected location or more action

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">

if you faced build error in fresh project you need to follow those instruction [#40]

1) remove flutter_osm_plugin from pubspec, after that pub get
2) open android module in android studio ( right click in name of project -> flutter-> open android module in android studio)
3) update gradle version to 4.1.1 ( ide will show popup to make update)
4) update kotlin version to 1.4.21 & re-build the project
5) re-add flutter_osm_plugin in pubspec , pub get ( or flutter clean & pub get )

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top