mapbox_api 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new64

mapbox-api #

This package aim to :

🚧 WIP Notice #

This is a work in progress, feel free open an issue for questions and remarks. (PR are welcome :))

Examples #

See examples/examples.dart

import 'package:mapbox_api/mapbox_api.dart';

MapboxApi mapbox = MapboxApi(
  accessToken: '<Mapbox API token>',
);

Get your API token on mapbox.com

Request directions services

DirectionsApiResponse response = await mapbox.directions.request(
  profile: NavigationProfile.DRIVING_TRAFFIC,
  overview: NavigationOverview.FULL,
  geometries: NavigationGeometries.POLYLINE6,
  steps: true,
  coordinates: <List<double>>[
    <double>[
      37.786060, // latitude
      -122.246225, // longitude
    ],
    <double>[
      37.785939, // latitude
      -122.194292, // longitude
    ],
  ],
);

if (response.error == null) {
  // response.routes ...
  // response.waypoints ...
}

Request map matching services

MapMatchingApiResponse response = await mapbox.mapMatching.request(
  profile: NavigationProfile.WALKING,
  geometries: NavigationGeometries.GEOJSON,
  tidy: true,
  coordinates: <List<double>>[
    <double>[
      37.786060, // latitude
      -122.246225, // longitude
    ],
    <double>[
      37.785939, // latitude
      -122.194292, // longitude
    ],
  ],
);

if (response.error == null) {
  // response.matchings ...
  // response.tracepoints ...
}

Supported API #

Maps #

ServiceImplemented
Vector Tiles✖️
Taster Tiles✖️
Static Images✖️
Static Tiles✖️
Styles✖️
Tilequery✖️
Uploads✖️
Mapbox Tiling Service✖️
Datasets✖️
Fonts✖️
ServiceImplemented
Directions
Isochrone
Map Matching
Matrix
Optimization
ServiceImplemented
Geocoding✖️

If you are looking for geocoding, take a look at ketanchoyal/mapbox_search

Accounts #

ServiceImplemented
Tokens✖️

This SDK will work perfectly with flutter-mapbox-gl to display retrieved data (will work with any other package too). You may also need polyline package to convert polylines strings to coordinates.

0.1.2 2020-07-01 #

  • Updated example folder

0.1.1 2020-07-01 #

  • Added example folder

0.1.0 2020-07-01 #

  • Initial release

example/example.dart

import 'package:mapbox_api/mapbox_api.dart';

void main() async {
  MapboxApi mapbox = MapboxApi(
    accessToken: '<Mapbox API token>',
  );

  DirectionsApiResponse response = await mapbox.directions.request(
    profile: NavigationProfile.DRIVING_TRAFFIC,
    overview: NavigationOverview.FULL,
    geometries: NavigationGeometries.POLYLINE6,
    steps: true,
    coordinates: <List<double>>[
      <double>[
        37.786060, // latitude
        -122.246225, // longitude
      ],
      <double>[
        37.785939, // latitude
        -122.194292, // longitude
      ],
    ],
  );

  if (response.error != null) {
    if (response.error is NavigationNoRouteError) {
      // handle NoRoute response
    } else if (response.error is NavigationNoSegmentError) {
      // handle NoSegment response
    }

    return;
  }

  if (response.routes.isNotEmpty) {
    final route = response.routes[0];
    final eta = Duration(
      seconds: route.duration.toInt(),
    );
    print(eta.toString());

    /*
    // Draw direction to mapbox_gl (flutter)

    import 'package:mapbox_gl/mapbox_gl.dart';
    import 'package:polyline/polyline.dart';

    final polyline = Polyline.Decode(
      encodedString: route.geometry as String,
      precision: 6,
    );
    final coordinates = polyline.decodedCoords;
    final path = <LatLng>[];

    for (var i = 0; i < coordinates.length; i++) {
      path.add(
        LatLng(
          coordinates[i][0],
          coordinates[i][1],
        ),
      );
    }

    if (path.length > 0) {
      // here we assume that controller was created from flutter and mapbox_gl
      final controller = MapboxMapController();

      await controller.addLine(
        LineOptions(
          geometry: path,
          lineColor: "#2196F3",
          lineWidth: 3.0,
          lineOpacity: 1,
          draggable: false,
        ),
      );
    }
    */
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  mapbox_api: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:mapbox_api/mapbox_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
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]
64
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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
http ^0.12.1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
http_parser 3.1.4
meta 1.2.2 1.3.0-nullsafety
path 1.7.0
pedantic 1.9.2
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety