mapbox_search 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

Pub

About #

This package provides easy api calls to MapBox Search API.

Also, it contains an static map image generator 😆.

Migration to 2.0 #

Before 2.0 this library depended on Flutter SDK, preventing its usage on other platforms such as a backend, CLI apps, Dart2Javascript, etc...

Now all the Flutter related code, such as the MapBoxSearchWidget was moved to a separated library: mapbox_search_flutter.

For that reason, you cannot use the Colors class anymore on you Flutter project. Instead use map_box_search's Color.rgb constructor, passing the values as parameters:

var myColor = Colors.redAccent; //Flutter's Color class
var mapBoxColor = Color.rgb( myColor.red, myColor.green, myColor.blue);

Installing #

First of all you must acquire an API key on the MapBox website https://www.mapbox.com/

Then, add the following to your pubspec.yaml file:

dependencies:
  mapbox_search: any

Examples #

Reverse GeoCoding #

var reverseGeoCoding = ReverseGeoCoding(
    apiKey: 'API Key',
    limit: 5,
);

Future<List<MapBoxPlace>> getPlaces() =>
  reverseGeoCoding.getAddress(
    Location(lat: 72.0, lng: 76.00),
);

Places Seach #

var placesSearch = PlacesSearch(
    apiKey: 'API Key',
    limit: 5,
);

Future<List<MapBoxPlace>> getPlaces() =>
  placesSearch.getPlaces("New York");

Static Image #

MapBoxStaticImage staticImage = MapBoxStaticImage(
    apiKey:
        "API Key");

Image With Polyline #

    String getStaticImageWithPolyline() => staticImage.getStaticUrlWithPolyline(
      point1: Location(lat: 37.77343, lng: -122.46589),
      point2: Location(lat: 37.75965, lng: -122.42816),
      marker1: MapBoxMarker( markerColor: Colors.black, markerLetter: 'p', markerSize: MarkerSize.LARGE),
      msrker2: MapBoxMarker(
          markerColor: Color.rgb(244, 67, 54),
          markerLetter: 'q',
          markerSize: MarkerSize.SMALL),
      height: 300,
      width: 600,
      zoomLevel: 16,
      style: MapBoxStyle.Mapbox_Dark,
      path: MapBoxPath(pathColor: Colors.red, pathOpacity: 0.5,     pathWidth: 5),
      render2x: true);

Image with Marker #

String getStaticImageWithMarker() => staticImage.getStaticUrlWithMarker(
  center: Location(lat: 37.77343, lng: -122.46589),
  marker: MapBoxMarker(
      markerColor: Color.rgb(0, 0, 0), markerLetter: 'p', markerSize: MarkerSize.LARGE),
  height: 300,
  width: 600,
  zoomLevel: 16,
  style: MapBoxStyle.Mapbox_Streets,
  render2x: true,
);

Image without Marker #

String getStaticImageWithoutMarker() => staticImage.getStaticUrlWithoutMarker(
    center: Location(lat: 37.75965, lng: -122.42816),
    height: 300,
    width: 600,
    zoomLevel: 16,
    style: MapBoxStyle.Mapbox_Outdoors,
    render2x: true,
  );

Screenshots #

Static Map Image #

Static Map Image

Search Widget #

DemoDemo

[2.0.0] - 12 February 2020. #

  • Breaking changes(migration from v1.x ro v2.0)

[2.0.0-dev] - 01 February 2020. #

  • Removed 'flutter' dependency.

All Flutter code, inclusing 'MapBoxPlaceSearchWidget' has been moved to library mapbox_search_flutter. Check README for more details.

[1.0.7] - 29 January 2020. #

  • Added Places Search for querying places by text.
  • Fixed limit and country parameters for ReverseGeocoding.

[1.0.6] - 20 January 2020. #

  • Added 'address' property to the Properties class.

[1.0.5] - 20 Jan 2020 #

  • Search text in search Widget localized

[1.0.4] - 19 October 2019. #

  • Reverse Geocoding query type set to dynamic(String or double)

[1.0.3] - 10 September 2019. #

  • Reverse Geocoding returning empty list bug Solved

[1.0.2] - 30 August 2019. #

Feature:

  • Reverse Geocoding Added

[1.0.1] - 27 August 2019. #

Feature:

  • add defaultPathPolyline and add assert(Merge Request)

[1.0.0] - 26 August 2019. #

Initial release.

Feature:

  • Places Search with prediction
  • Static Image with marker
  • Static Image without Marker
  • Static Image with Polyline path

example/main.dart

import 'package:mapbox_search/mapbox_search.dart';

Future<void> main() async {
  String apiKey = "YOU API KEY HERE"; //Set up a test api key before running

  await geoCoding(apiKey).catchError(print);
  await placesSearch(apiKey).catchError(print);
}

///Reverse GeoCoding sample call
Future geoCoding(String apiKey) async {
  var geoCodingService = ReverseGeoCoding(
    apiKey: apiKey,
    country: "BR",
    limit: 5,
  );

  var addresses = await geoCodingService.getAddress(Location(
    lat: -19.984846,
    lng: -43.946852,
  ));

  print(addresses);
}

///Places search sample call
Future placesSearch(String apiKey) async {
  var placesService = PlacesSearch(
    apiKey: apiKey,
    country: "BR",
    limit: 5,
  );

  var places = await placesService.getPlaces(
    "patio",
    location: Location(
      lat: -19.984634,
      lng: -43.9502958,
    ),
  );

  print(places);
}

Use this package as a library

1. Depend on it

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


dependencies:
  mapbox_search: ^2.0.0

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_search/mapbox_search.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
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]
91
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
color ^2.1.1 2.1.1
http ^0.12.0+4 0.12.0+4
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
http_parser 3.1.4
meta 1.1.8
path 1.6.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.9.0 1.9.0
test ^1.9.3