map_view 0.0.5

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

map_view

A flutter plugin for displaying google maps on iOS and Android

Please note: API changes are likely as we continue to develop this plugin.

Getting Started

iOS

1. Set the NSLocationWhenInUseUsageDescription in your Info.plist
2. Your Google Map API key must be set using the MapView.setApiKey prior to displaying the MapView

Android

1. In your AndroidManifest.xml, add the following uses-permission
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
2. Also add your Google Maps API Key
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
3. Add the MapActivity to your AndroidManifest.xml
    <activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
4. In your android/build.gradle file. Under buildScript dependencies add:
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
   
You can refer to the example project if you run into any issues with these steps.

Features

  • [X] iOS Support
  • [X] Android Support
  • [X] Toolbar support
  • [X] Update Camera position
  • [X] Add Map pins
  • [X] Receive map pin touch callbacks
  • [X] Receive map touch callbacks
  • [X] Receive location change callbacks
  • [X] Receive camera change callbacks
  • [X] Zoom to a set of annotations
  • [X] Customize Pin color

Upcoming

  • [ ] Customize pin image
  • [ ] Remove markers
  • [ ] Bounds geometry functions
  • [ ] Polyline support

Usage examples

Show a map ( with a toolbar )

mapView.show(
    new MapOptions(
        showUserLocation: true,
        initialCameraPosition: new CameraPosition(
            new Location(45.5235258, -122.6732493), 14.0),
        title: "Recently Visited"),
    toolbarActions: [new ToolbarAction("Close", 1)]);

Get notified when the map is ready

mapView.onMapReady.listen((_) {
  print("Map ready");
});

Add multiple pins to the map

mapView.setMarkers(<Marker>[
  new Marker("1", "Work", 45.523970, -122.663081, color: Colors.blue),
  new Marker("2", "Nossa Familia Coffee", 45.528788, -122.684633),
]);

Add a single pin to the map

mapView.addMarker(new Marker("3", "10 Barrel", 45.5259467, -122.687747,
    color: Colors.purple));
    

Zoom to fit all the pins on the map

mapView.zoomToFit(padding: 100);

Receive location updates of the users current location

mapView.onLocationUpdated
    .listen((location) => print("Location updated $location"));

Receive marker touches

mapView.onTouchAnnotation.listen((marker) => print("marker tapped"));

Receive map touches

mapView.onMapTapped
    .listen((location) => print("Touched location $location"));

Receive camera change updates

mapView.onCameraChanged.listen((cameraPosition) =>
    this.setState(() => this.cameraPosition = cameraPosition));

Receive toolbar actions

mapView.onToolbarAction.listen((id) {
  if (id == 1) {
    _handleDismiss();
  }
});

Get the current zoom level

double zoomLevel = await mapView.zoomLevel;

Get the maps center location

Location centerLocation = await mapView.centerLocation;

Get the visible markers on screen

List<Marker> visibleAnnotations = await mapView.visibleAnnotations;

[0.0.1] - 11-07-2017

  • Full Screen Map Support
  • iOS Support
  • Android Support
  • Support for adding map pins
  • Support for location change updates
  • Support for camera position updates
  • Support for marker touch callbacks
  • Support for map tap callbacks
  • Support for zooming to annotation(s)
  • Support for setting camera position
  • Support for querying current viewport information
  • Support for getting current visible pins
  • Support for toolbar items

[0.0.2] - 11-07-2017

  • Improved examples

[0.0.3] - 11-08-2017

[0.0.4] - 11-08-2017

  • Updated Authors for pub.dartlang.com

[0.0.5] - 11-14-2017

  • Improved setup documentation

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:map_view/camera_position.dart';
import 'package:map_view/location.dart';
import 'package:map_view/map_options.dart';
import 'package:map_view/map_view.dart';
import 'package:map_view/marker.dart';
import 'package:map_view/toolbar_action.dart';

void main() {
  MapView.setApiKey("<your_api_key>");
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {
  MapView mapView = new MapView();
  CameraPosition cameraPosition;
  var compositeSubscription = new CompositeSubscription();

  @override
  initState() {
    super.initState();
    cameraPosition = new CameraPosition(new Location(0.0, 0.0), 0.0);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Map View Example'),
          ),
          body: new Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              new Container(
                padding: new EdgeInsets.only(top: 10.0),
                child: new RaisedButton(
                  color: Colors.blue,
                  onPressed: showMap,
                  child: new Text(
                    "Show Map",
                    style: new TextStyle(color: Colors.white),
                  ),
                ),
              ),
              new Center(
                child: new Container(
                  padding: new EdgeInsets.only(top: 25.0),
                  child: new Text(
                      "Camera Position: ${cameraPosition.center.latitude}, ${cameraPosition.center.longitude}. Zoom: ${cameraPosition.zoom}"),
                ),
              ),
            ],
          )),
    );
  }

  showMap() {
    mapView.show(
        new MapOptions(
            showUserLocation: true,
            initialCameraPosition: new CameraPosition(
                new Location(45.5235258, -122.6732493), 14.0),
            title: "Recently Visited"),
        toolbarActions: [new ToolbarAction("Close", 1)]);

    var sub = mapView.onMapReady.listen((_) {
      mapView.setMarkers(<Marker>[
        new Marker("1", "Work", 45.523970, -122.663081, color: Colors.blue),
        new Marker("2", "Nossa Familia Coffee", 45.528788, -122.684633),
      ]);
      mapView.addMarker(new Marker("3", "10 Barrel", 45.5259467, -122.687747,
          color: Colors.purple));

      mapView.zoomToFit(padding: 100);
    });
    compositeSubscription.add(sub);

    sub = mapView.onLocationUpdated
        .listen((location) => print("Location updated $location"));
    compositeSubscription.add(sub);

    sub = mapView.onTouchAnnotation
        .listen((annotation) => print("annotation tapped"));
    compositeSubscription.add(sub);

    sub = mapView.onMapTapped
        .listen((location) => print("Touched location $location"));
    compositeSubscription.add(sub);

    sub = mapView.onCameraChanged.listen((cameraPosition) =>
        this.setState(() => this.cameraPosition = cameraPosition));
    compositeSubscription.add(sub);

    sub = mapView.onToolbarAction.listen((id) {
      if (id == 1) {
        _handleDismiss();
      }
    });
    compositeSubscription.add(sub);
  }

  _handleDismiss() async {
    double zoomLevel = await mapView.zoomLevel;
    Location centerLocation = await mapView.centerLocation;
    List<Marker> visibleAnnotations = await mapView.visibleAnnotations;
    print("Zoom Level: $zoomLevel");
    print("Center: $centerLocation");
    print("Visible Annotation Count: ${visibleAnnotations.length}");
    mapView.dismiss();
    compositeSubscription.cancel();
  }
}

class CompositeSubscription {
  Set<StreamSubscription> _subscriptions = new Set();

  void cancel() {
    for (var n in this._subscriptions) {
      n.cancel();
    }
    this._subscriptions = new Set();
  }

  void add(StreamSubscription subscription) {
    this._subscriptions.add(subscription);
  }

  void addAll(Iterable<StreamSubscription> subs) {
    _subscriptions.addAll(subs);
  }

  bool remove(StreamSubscription subscription) {
    return this._subscriptions.remove(subscription);
  }

  bool contains(StreamSubscription subscription) {
    return this._subscriptions.contains(subscription);
  }

  List<StreamSubscription> toList() {
    return this._subscriptions.toList();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  map_view: ^0.0.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:map_view/map_view.dart';
  
Version Uploaded Documentation Archive
0.0.14 Jul 20, 2018 Go to the documentation of map_view 0.0.14 Download map_view 0.0.14 archive
0.0.13 Jul 18, 2018 Go to the documentation of map_view 0.0.13 Download map_view 0.0.13 archive
0.0.12 Apr 17, 2018 Go to the documentation of map_view 0.0.12 Download map_view 0.0.12 archive
0.0.11 Apr 16, 2018 Go to the documentation of map_view 0.0.11 Download map_view 0.0.11 archive
0.0.10 Dec 30, 2017 Go to the documentation of map_view 0.0.10 Download map_view 0.0.10 archive
0.0.9 Dec 30, 2017 Go to the documentation of map_view 0.0.9 Download map_view 0.0.9 archive
0.0.8 Dec 29, 2017 Go to the documentation of map_view 0.0.8 Download map_view 0.0.8 archive
0.0.7 Dec 29, 2017 Go to the documentation of map_view 0.0.7 Download map_view 0.0.7 archive
0.0.6 Dec 27, 2017 Go to the documentation of map_view 0.0.6 Download map_view 0.0.6 archive
0.0.5 Nov 14, 2017 Go to the documentation of map_view 0.0.5 Download map_view 0.0.5 archive

All 14 versions...

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

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Health issues and suggestions

Document public APIs (-9.64 points)

54 out of 56 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

The description is too short. (-20 points)

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-v0.1 release. (-10 points)

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

Package is getting outdated. (-5.75 points)

The package was released 55 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8