google_map_location_picker 2.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

google_map_location_picker Pub

Location picker using the official google_maps_flutter.

I made This plugin because google deprecated Place Picker.

Using #

For message localization inside the library please add in MaterialApp

import 'package:google_map_location_picker/generated/i18n.dart' as location_picker;

MaterialApp(
  localizationsDelegates: const [
    location_picker.S.delegate,
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  supportedLocales: const <Locale>[
    Locale('en', ''),
    Locale('ar', ''),
  ],
  home: ...
)
import 'package:google_map_location_picker/google_map_location_picker.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

LocationResult result = await LocationPicker.pickLocation(context, apiKey);

Getting Started #

Get an API key at https://cloud.google.com/maps-platform/.

and don't forget to enable in https://console.cloud.google.com/google/maps-apis/

  • Maps SDK for Android
  • Maps SDK for iOS
  • Places API
  • Geolocation API
  • Geocoding API

Android #

Specify your API key in the application manifest android/app/src/main/AndroidManifest.xml:

<manifest ...
  <application ...
    <meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR KEY HERE"/>

iOS #

Specify your API key in the application delegate ios/Runner/AppDelegate.m:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"YOUR KEY HERE"];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end

Or in your swift code, specify your API key in the application delegate ios/Runner/AppDelegate.swift:

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("YOUR KEY HERE")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

Note #

The following permissions are not required to use Google Maps Android API v2, but are recommended.

android.permission.ACCESS_COARSE_LOCATION Allows the API to use WiFi or mobile cell data (or both) to determine the device's location. The API returns the location with an accuracy approximately equivalent to a city block.

android.permission.ACCESS_FINE_LOCATION Allows the API to determine as precise a location as possible from the available location providers, including the Global Positioning System (GPS) as well as WiFi and mobile cell data.


You must also explicitly declare that your app uses the android.hardware.location.network or android.hardware.location.gps hardware features if your app targets Android 5.0 (API level 21) or higher and uses the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to receive location updates from the network or a GPS, respectively.

<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false"  />

The following permissions are defined in the package manifest, and are automatically merged into your app's manifest at build time. You don't need to add them explicitly to your manifest:

android.permission.INTERNET Used by the API to download map tiles from Google Maps servers.

android.permission.ACCESS_NETWORK_STATE Allows the API to check the connection status in order to determine whether data can be downloaded.

Credits #

The google map from Flutter's google_maps_flutter package

current location and permission from BaseflowIT's flutter-geolocator package.

The search bar from Degreat's locationpicker package.

2.1.0 #

  • Make location permission optional, required by default.

2.0.2+2 #

  • Fix NPE when the user forget to initialize localization.

2.0.2+1 #

  • fix minor typo in Portuguese translation.

2.0.2 #

  • added Portuguese translation thanks @mariosemedo.

2.0.1 #

  • I added Turkish language file thanks @furkankurt.

2.0.0+3 #

  • updated Readme to reflect the latest version of the lib.

2.0.0+2 #

  • updated dependencies to the latest version.

2.0.0+1 #

  • updated dependencies to the latest version.

2.0.0 #

  • Fix permission error dialog.
  • Added arabic lionization.

1.0.5+3 #

  • updated dependencies to the latest version.

1.0.5+2 #

  • updated google_maps_flutter: ^0.5.20+2

1.0.5+1 #

  • updated google_maps_flutter: ^0.5.19+2

1.0.5 #

  • updated google_maps_flutter: ^0.5.19

1.0.4 #

  • remove ConstrainedBox around address card as the font changes sometimes cutouts happen.

1.0.3 #

  • remove some useless logging.

1.0.2 #

  • fix the address card mix height it and sometimes it's cutout.

1.0.1 #

  • remove unused code.

1.0.0 #

  • fix bug with requesting location permission
  • fix the address card mix height it and sometimes it's cutout.
  • added library and export only the important parts

0.2.0 #

  • now retuning the address plus LatLng
  • do the reverse geocoding with google web api instead of the native lib.

0.1.1 #

  • Updated min dart version to 2.2.2.
  • fix some formatting issues.

0.1.0 #

  • Added place search feature.

0.0.5 #

  • updated deps

0.0.4 #

  • remove permissions from package AndroidManifest.xml as it's already added by google maps.
  • improved README

0.0.2 #

  • added the permissions to the package directly.

0.0.1 #

  • initial release.

example/README.md

example/dio.dart #

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:google_map_location_picker/generated/i18n.dart'
    as location_picker;
import 'package:google_map_location_picker/google_map_location_picker.dart';
import 'package:google_map_location_picker_example/keys.dart';

import 'generated/i18n.dart';

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

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

class _MyAppState extends State<MyApp> {
  LocationResult _pickedLocation;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'location picker',
      localizationsDelegates: const [
        location_picker.S.delegate,
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const <Locale>[
        Locale('en', ''),
        Locale('ar', ''),
      ],
      home: Scaffold(
        appBar: AppBar(
          title: const Text('location picker'),
        ),
        body: Builder(builder: (context) {
          return Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  onPressed: () async {
                    LocationResult result = await LocationPicker.pickLocation(
                      context,
                      apiKey,
                    );
                    print("result = $result");
                    setState(() => _pickedLocation = result);
                  },
                  child: Text('Pick location'),
                ),
                Text(_pickedLocation.toString()),
              ],
            ),
          );
        }),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  google_map_location_picker: ^2.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:google_map_location_picker/google_map_location_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
88
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]
94
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
android_intent ^0.3.3+2 0.3.4+3
flutter 0.0.0
flutter_localizations 0.0.0
geolocator ^5.1.4 5.1.4+2
google_maps_flutter ^0.5.21+7 0.5.21+8
http ^0.12.0+2 0.12.0+2
intl >=0.15.8 <=0.16.0 0.15.8 0.16.0
intl_translation ^0.17.6 0.17.7
provider ^3.1.0 3.1.0+1
stack_trace ^1.9.3 1.9.3
Transitive dependencies
analyzer 0.38.5 0.39.0
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.2
front_end 0.1.27 0.1.28
glob 1.2.0
google_api_availability 2.0.1
html 0.14.0+3
http_parser 3.1.3
js 0.6.1+1
kernel 0.3.27 0.3.28
location_permissions 2.0.3
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
petitparser 2.4.0
platform 2.2.1
pub_semver 1.4.2
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
flutter_test