mapbox_geocoding 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

Pub

Dart Mapbox Geocoding API (not official) #

A Flutter package Mapbox Geocoding API. Package is not official product of mapbox.

This project is a library to use Mapbox Geocoding API from dart scripts.

Documentation #

Library documentation is here.

Usage #

To use this library in your code:

  • add a dependency in your pubspec.yaml :

    dependencies:
      mapbox_geocoding: "^last_version"
    
  • add import in your dart code:

    import 'package:mapbox_geocoding/mapbox_geocoding.dart';
    

Please create/use Mapbox account to obtain Mapbox access token.

If you have Mapbox account, you can reach access token from Mapbox account dashboard.

A very simple example :

import 'package:mapbox_geocoding/mapbox_geocoding.dart';
import 'package:mapbox_geocoding/model/forward_geocoding.dart';

MapboxGeocoding geocoding = MapboxGeocoding('YOUR_ACCESS_TOKEN');

///Forward geocoding. Get latitude and longitude from place name.
getCoordinates(String city) async {
    try {
        ForwardGeocoding forwardModel = await geocoding.forwardModel(city);
        return forwardModel.features[0].center;
    } catch (Excepetion) {
        return 'Forward Geocoding Error';
    }
}
///Reverse geocoding. Get place name from latitude and longitude.
getCity(double lat, double lng, String apiKey) async {
    try {
        ReverseGeocoding reverseModel = await geocoding.reverseModel(lat, lng);
        return reverseModel.features[0].placeName;
    } catch (Excepetion) {
        return 'Reverse Geocoding Error';
    }
}

License #

MIT

[0.1.1] - 2020-05-08 #

  • Readme updated.

[0.1.0] - 2020-05-08 #

  • Access token moved main class.

[0.0.11] - 2020-05-08 #

  • Health suggestions fixed.

[0.0.10] - 2020-05-08 #

  • Health suggestions fixed.

[0.0.9] - 2020-05-08 #

  • Health suggestions fixed.

[0.0.8] - 2020-05-08 #

  • Remove flutter dependencies.
  • Change log order fixed.

[0.0.7] - 2020-05-08 #

  • Geocoding optional parameters bug fixed.
  • Example updated.

[0.0.6] - 2020-05-08 #

[0.0.5] - 2020-05-07 #

[0.0.4] - 2020-05-07 #

[0.0.3] - 2020-05-07 #

  • Readme updated.
  • Example updated.
  • Forward and reverse geocoding model' documentation in [dart] code.

[0.0.2] - 2020-05-07 #

  • Pub.dev changes.
  • License added.
  • Example created. (Do not use!)
  • Github repository specified.

[0.0.1] - 2020-05-07 #

  • First version.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:mapbox_geocoding/mapbox_geocoding.dart';
import 'package:mapbox_geocoding/model/forward_geocoding.dart';
import 'package:mapbox_geocoding/model/reverse_geocoding.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  MapboxGeocoding geocoding = MapboxGeocoding('YOUR_ACCESS_TOKEN');

  ///Forward geocoding. Get latitude and longitude from place name.
  getCoordinates(String city) async {
    try {
      ForwardGeocoding forwardModel =
          await geocoding.forwardModel(city, limit: 3, language: 'tr');
      return forwardModel.features[0].center;
    } catch (Excepetion) {
      return 'Forward Geocoding Error';
    }
  }

  ///Reverse geocoding. Get place name from latitude and longitude.
  getCity(double lat, double lng) async {
    try {
      ReverseGeocoding reverseModel =
          await geocoding.reverseModel(lat, lng, limit: 7, types: 'region');
      return reverseModel.features[0].placeName;
    } catch (Excepetion) {
      return 'Reverse Geocoding Error';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              getCoordinates('Istanbul'),
            ),
            Text(
              getCity(41.0, 29.0),
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  mapbox_geocoding: ^0.1.1

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_geocoding/mapbox_geocoding.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
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]
78
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
http ^0.12.0+4 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13
http_parser 3.1.4
meta 1.1.8
path 1.7.0
pedantic 1.9.0 1.9.1
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0