geocoder 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 90

geocoder

Forward and reverse geocoding.

Usage

Import package:geocoder/geocoder.dart, and use the Geocoder.local to access geocoding services provided by the device system.

Example:

import 'package:geocoder/geocoder.dart';

// From a query
final query = "1600 Amphiteatre Parkway, Mountain View";
var addresses = await Geocoder.local.findAddressesFromQuery(query);
var first = addresses.first;
print("${first.featureName} : ${first.coordinates}");

// From coordinates
final coordinates = new Coordinates(1.10, 45.50);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");

You can alternatively use Geocoder.google member for requesting distant data from google services instead of native ones.

You will find links to the API docs on the pub page.

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:geocoder/geocoder.dart';
import 'package:geocoder/services/base.dart';
import 'package:geocoder_example/widgets.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class AppState extends InheritedWidget {
  const AppState({
    Key key,
    this.mode,
    Widget child,
  }) : assert(mode != null),
        assert(child != null),
        super(key: key, child: child);

  final Geocoding mode;

  static AppState of(BuildContext context) {
    return context.inheritFromWidgetOfExactType(AppState);
  }

  @override
  bool updateShouldNotify(AppState old) => mode != old.mode;
}

class GeocodeView extends StatefulWidget {

  GeocodeView();

  @override
  _GeocodeViewState createState() => new _GeocodeViewState();
}

class _GeocodeViewState extends State<GeocodeView> {

  _GeocodeViewState();

  final TextEditingController _controller = new TextEditingController();

  List<Address> results = [];

  bool isLoading = false;

  Future search() async {

    this.setState(() {
      this.isLoading = true;
    });

    try{
      var geocoding = AppState.of(context).mode;
      var results = await geocoding.findAddressesFromQuery(_controller.text);
      this.setState(() {
        this.results = results;
      });
    }
    catch(e) {
      print("Error occured: $e");
    }
    finally {
      this.setState(() {
        this.isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Column(
        children: <Widget>[
          new Card(
            child: new Padding(
              padding: const EdgeInsets.all(10.0),
              child: new Row(
                children: <Widget>[
                  new Expanded(
                    child: new TextField(
                      controller: _controller,
                      decoration: new InputDecoration(hintText: "Enter an address"),
                    ),
                  ),
                  new IconButton(icon: new Icon(Icons.search), onPressed: () => search())
                ],
              ),
            ),
          ),
          new Expanded(child: new AddressListView(this.isLoading, this.results)),
        ]);
  }
}

class ReverseGeocodeView extends StatefulWidget {

  ReverseGeocodeView();

  @override
  _ReverseGeocodeViewState createState() => new _ReverseGeocodeViewState();
}

class _ReverseGeocodeViewState extends State<ReverseGeocodeView> {

  final TextEditingController _controllerLongitude = new TextEditingController();
  final TextEditingController _controllerLatitude = new TextEditingController();

  _ReverseGeocodeViewState();

  List<Address> results = [];

  bool isLoading = false;

  Future search() async {


    this.setState(() {
      this.isLoading = true;
    });

    try{
      var geocoding = AppState.of(context).mode;
      var longitude = double.parse(_controllerLongitude.text);
      var latitude = double.parse(_controllerLatitude.text);
      var results = await geocoding.findAddressesFromCoordinates(new Coordinates(latitude, longitude));
      this.setState(() {
        this.results = results;
      });
    }
    catch(e) {
      print("Error occured: $e");
    }
    finally {
      this.setState(() {
        this.isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Column(
        children: <Widget>[
          new Card(
            child: new Padding(
              padding: const EdgeInsets.all(10.0),
              child: new Row(
                children: <Widget>[
                  new Expanded(
                    child: new Column(
                      children: <Widget>[
                        new TextField(
                          controller: _controllerLatitude,
                          decoration: new InputDecoration(hintText: "Latitude"),
                        ),
                        new TextField(
                          controller: _controllerLongitude,
                          decoration: new InputDecoration(hintText: "Longitude"),
                        ),
                      ],
                    ),
                  ),
                  new IconButton(icon: new Icon(Icons.search), onPressed: () => search())
                ],
              ),
            ),
          ),
          new Expanded(child: new AddressListView(this.isLoading, this.results)),
        ]);
  }
}

class _MyAppState extends State<MyApp> {

  Geocoding geocoding = Geocoder.local;

  final Map<String, Geocoding> modes = {
    "Local" : Geocoder.local,
    "Google (distant)" : Geocoder.google("AIzaSyBa7VDCPLDtvm_XkkY69FpEuuRWo-3NYq8"),
  };

  void _changeMode(Geocoding mode) {
    this.setState(() {
      geocoding = mode;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new AppState(
      mode: this.geocoding,
      child: new MaterialApp(
        home: new DefaultTabController(
          length: 2,
          child: new Scaffold(
            appBar: new AppBar(
              title: new Text('Geocoder'),
              actions: <Widget>[
                new PopupMenuButton<Geocoding>( // overflow menu
                  onSelected: _changeMode,
                  itemBuilder: (BuildContext context) {
                    return modes.keys.map((String mode) {
                      return new CheckedPopupMenuItem<Geocoding>(
                        checked: modes[mode] == this.geocoding,
                        value: modes[mode],
                        child: new Text(mode),
                      );
                    }).toList();
                  },
                ),
              ],
              bottom: new TabBar(
                tabs:  [
                   new Tab(
                    text: "Query",
                    icon: new Icon(Icons.search),
                  ),
                   new Tab(
                     text: "Coordinates",
                     icon: new Icon(Icons.pin_drop),
                   ),
                ],
              ),
            ),
            body: new TabBarView(
                children: <Widget>[
                  new GeocodeView(),
                  new ReverseGeocodeView(),
                ]),
          ),
        ),
      ),
    );
  }
}

1. Depend on it

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


dependencies:
  geocoder: "^0.0.1"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:geocoder/geocoder.dart';
        
Version Uploaded Documentation Archive
0.0.1 Feb 4, 2018 Go to the documentation of geocoder 0.0.1 Download geocoder 0.0.1 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6
  • Flutter: 0.3.2

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
82 / 100
Health:
Code health derived from static analysis. [more]
97 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
90
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 6 hints.

    Run flutter format to format lib/model.dart.

    Run flutter format to format lib/services/base.dart.

    Similar analysis of the following files failed:

    • lib/services/distant_google.dart (hint)
    • lib/services/local.dart (hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.9
meta 1.1.2
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6