项目作者: hexa-apps

项目描述 :
Flutter package which provides Mapbox Geocoding API
高级语言: Dart
项目地址: git://github.com/hexa-apps/mapbox_geocoding.git
创建时间: 2020-10-07T08:14:10Z
项目社区:https://github.com/hexa-apps/mapbox_geocoding

开源协议:MIT License

下载


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.

Table of Contents

Documentation

Library documentation is here.

Usage

To use this library in your code:

  • add a dependency in your pubspec.yaml :

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

    1. 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 :

  1. import 'package:mapbox_geocoding/mapbox_geocoding.dart';
  2. import 'package:mapbox_geocoding/model/forward_geocoding.dart';
  3. MapboxGeocoding geocoding = MapboxGeocoding('YOUR_ACCESS_TOKEN');
  4. ///Forward geocoding. Get latitude and longitude from place name.
  5. getCoordinates(String city) async {
  6. try {
  7. ForwardGeocoding forwardModel = await geocoding.forwardModel(city);
  8. return forwardModel.features[0].center;
  9. } catch (Excepetion) {
  10. return 'Forward Geocoding Error';
  11. }
  12. }
  13. ///Reverse geocoding. Get place name from latitude and longitude.
  14. getCity(double lat, double lng, String apiKey) async {
  15. try {
  16. ReverseGeocoding reverseModel = await geocoding.reverseModel(lat, lng);
  17. return reverseModel.features[0].placeName;
  18. } catch (Excepetion) {
  19. return 'Reverse Geocoding Error';
  20. }
  21. }

License

MIT