🌍 Map location picker component for flutter Based on google_maps_flutter

Overview

google_map_location_picker Pub

Location picker using the official google_maps_flutter.

I made This plugin because google deprecated Place Picker.

Demo

Using

Pubspec changes:

      dependencies: 
      
        google_maps_flutter: ^0.5.30
        google_map_location_picker: ^3.3.4
        flutter_localizations:
          sdk: flutter

For message localization inside the library please add in MaterialApp

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

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 showLocationPicker(context, apiKey);

Getting Started

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)
  }
}

you need also to define NSLocationWhenInUseUsageDescription

  <key>NSLocationWhenInUseUsageDescription</key>
  <string>This app needs your location to test the location feature of the Google Maps location picker plugin.</string>

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.

Restricting Autocomplete Search to Region

The LocationResults returned can be restricted to certain countries by passing an array of country codes into the countries parameter of showLocationPicker(). Countries must be two character, ISO 3166-1 Alpha-2 compatible. You can find code information at Wikipedia: List of ISO 3166 country codes or the ISO Online Browsing Platform.

The example below restricts Autocomplete Search to the United Arab Emirates and Nigeria

showLocationPicker(
context, "YOUR API KEY HERE",
initialCenter: LatLng(31.1975844, 29.9598339),
myLocationButtonEnabled: true,
layersButtonEnabled: true,
countries: ['AE', 'NG'],
);

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.

Comments
  • "Unnamed Place" issue

    I'm getting the "unnamed place" issue, but only on android. I set my api key in the manifest per the guide, and it's working fine on iOS. It is not showing any map, and it is showing "Unnamed Place" in the address section on the bottom. I have all 5 of the needed APIs enabled on the Google API console. Also, no map is showing either. Here is what the screen looks like.

    duplicate 
    opened by DanielSmith1239 15
  • iOS: fatal error: 'google_map_location_picker/google_map_location_picker-Swift.h' file not found

    iOS: fatal error: 'google_map_location_picker/google_map_location_picker-Swift.h' file not found

    Hi, I builded for iOS device and I got this error: === BUILD TARGET path_provider OF PROJECT Pods WITH CONFIGURATION Debug === /Users/wunu/workspace/flutter/.pub-cache/hosted/pub.flutter-io.cn/google_map_location_picker-2.1.0/ios/Classes/GoogleMapLocationPickerPlugin.m:2:9: fatal error: 'google_map_location_picker/google_map_location_picker-Swift.h' file not found #import <google_map_location_picker/google_map_location_picker-Swift.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

    version: google_map_location_picker: 2.1.0

    It is working fine on Android, please advise, thank you!

    opened by TennisAndy 9
  • I can't find location.

    I can't find location.

    I just run the example app and I am getting these exceptions and can't get any location only Lat and Long.

    I/flutter ( 3549): package:google_map_location_picker/src/map.dart 284:7 | GeolocationStatus.granted
    I/flutter ( 3549): package:google_map_location_picker/src/map.dart 60:7 | position = Lat: ***, Long: ***
    I/flutter ( 3549): package:google_map_location_picker/src/map.dart 284:7 | GeolocationStatus.granted
    I/Google Maps Android API( 3549): Google Play services package version: 19420039
    W/System  ( 3549): A resource failed to call release. 
    I/flutter ( 3549): onCameraMoveStarted#_lastMapPosition = LatLng(45.521563, -122.677433)
    I/flutter ( 3549): package:google_map_location_picker/src/map.dart 284:7 | GeolocationStatus.granted
    I/flutter ( 3549): RangeError (index): Invalid value: Valid value range is empty: 0
    I/flutter ( 3549): RangeError (index): Invalid value: Valid value range is empty: 0
    I/flutter ( 3549): onCameraIdle#_lastMapPosition = LatLng(***, ***)
    I/flutter ( 3549): package:google_map_location_picker/src/map.dart 284:7 | GeolocationStatus.granted
    I/flutter ( 3549): RangeError (index): Invalid value: Valid value range is empty: 0
    
    

    Screenshot_20191021-221135

    opened by pavel-birdy 8
  • what is this issue exactly i dont know ??

    what is this issue exactly i dont know ??

    The plugin google_api_availability doesn't have a main class defined in E:\flutter_installation\flutter.pub-cache\hosted\pub.dartlang.org\google_api_availability-2.0.4\android\src\main\java\com\baseflow\googleapiavailability\GoogleApiAvailabilityPlugin.java or E:\flutter_installation\flutter.pub-cache\hosted\pub.dartlang.org\google_api_availability-2.0.4\android\src\main\kotlin\com\baseflow\googleapiavailability\GoogleApiAvailabilityPlugin.kt. This is likely to due to an incorrect androidPackage: com.baseflow.googleapiavailability or mainClass entry in the plugin's pubspec.yaml. If you are the author of this plugin, fix the androidPackage entry or move the main class to any of locations used above. Otherwise, please contact the author of this plugin and consider using a different plugin in the meanwhile.

    opened by aTeamSolace 7
  • Loding issue with IOS

    Loding issue with IOS

    Hi,

    I am using version ^3.1.0. Its working fine in Android. But giving issue with IOS. It stuck in loading. The loading progress is never ending and nothing happens.

    Please let me know what could be the issue.

    Thanks, Shanvaz.M

    opened by avaan 7
  • How to restrict my api key

    How to restrict my api key

    Hi, We used your great package and as our app getting ready to production we started to review it from security point of view. Do you have any advice how can I restrict my api key? The standard app restriction would be the best but it doesn't work due to the simple api call. The problematic line is https://github.com/humazed/google_map_location_picker/blob/master/lib/src/map.dart#L242

    Any help would be appreciated

    opened by janosroden 7
  • set value to initialCenter is not working

    set value to initialCenter is not working

    Hi,

    Thank you for the wonderful library.

    I want to use this library in one of my flutter project. I am able to use a location picker(add location) but I want to use the same picker to allow user to change location. For that I tried to use it like below:

    LatLng location = getLatLng(state.latLng);
    result = await LocationPicker.pickLocation(
            context,
            Constants.GOOGLE_API_KEY,
            initialCenter: location,
    );
    

    but unfortunately its not pinned to specified location and always showing my current location. How can I set the pinned location while initiating picker ?

    opened by moriswala 7
  • Dark mode

    Dark mode

    Hello,

    as you suggested I started to implement a dark mode. I also added a few more customisation options. I think the map center button should be optional (which is not yet implemented). Also I think the satellite view is not necessary when custom map styles are possible. Unknown-4 Happy to discuss the changes :)

    opened by JesperBllnbm 6
  • No need to access GPS

    No need to access GPS

    Hi, First thank you for the plugin. One question: Why do you need the GPS enabled to pick a location? I mean you don't need it unless you want to share your own position. If my GPS is disabled, the plugin is not showing the map and I cannot pick a location, even through I want to share a position of something not related to my position at all. Do you think you can change that? If there is already the button for "Showing my position", I think it is enough no?

    Thank you

    opened by djsliders 6
  • Limit Location Search to a Country , Region....

    Limit Location Search to a Country , Region....

    Hi Ibrahim,

    Not sure if this already exist, is there a way to limit Location auto complete search to certain country? maybe additional iption to showLocationPicker. Thanks!

    -- Gab

    enhancement 
    opened by GabDorilag 5
  • Camera position different from the current location

    Camera position different from the current location

    I am trying to edit an entity that has a pair of Latitude and Longitude, so i edit it through this widget. I want it to show in the map the old location and not my current location. I am setting the automaticallyAnimateToCurrentLocation: as false, but this centers the camera tu a remote island idkwhere. Is there a way to set the camera at a certain LatLng?

    My code is the following:

    Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ RaisedButton( onPressed: () async { LocationResult result; if (initialLat != 0 || initialLong != 0) { result = await showLocationPicker( context, 'AIzaSyD8_lvGEpZodiVIfNTBE5sOzgRfeVHpFe4', initialCenter: LatLng(initialLat, initialLong), myLocationButtonEnabled: true, automaticallyAnimateToCurrentLocation: false, ); } else { result = await showLocationPicker( context, 'AIzaSyD8_lvGEpZodiVIfNTBE5sOzgRfeVHpFe4', myLocationButtonEnabled: true); } setState(() => _pickedLocation = result); setLat(_pickedLocation.latLng.latitude); setLong(_pickedLocation.latLng.longitude); }, child: Text('Mark your location!'), ), ], ), );

    Thanks in advance!

    opened by FabianGrob 5
  • This project is abandoned

    This project is abandoned

    Anyone coming here should consider this project abandoned since it has been more than 2 years since the last update and there is no sight of maintenance. You will need to look for alternatives

    opened by qaniel 0
  • Because engazwaterclient depends on google_map_location_picker ^4.1.7 which depends on provider ^5.0.0, provider ^5.0.0 is required. So, because engazwaterclient depends on provider ^6.0.3, version solving failed.

    Because engazwaterclient depends on google_map_location_picker ^4.1.7 which depends on provider ^5.0.0, provider ^5.0.0 is required. So, because engazwaterclient depends on provider ^6.0.3, version solving failed.

    Because engazwaterclient depends on google_map_location_picker ^4.1.7 which depends on provider ^5.0.0, provider ^5.0.0 is required. So, because engazwaterclient depends on provider ^6.0.3, version solving failed. pub get failed (1; So, because engazwaterclient depends on provider ^6.0.3, version solving failed.)

    opened by bezagroup 0
  • Getting issue when upgraded to flutter 3.0

    Getting issue when upgraded to flutter 3.0

    I'm getting below error when I upgraded to flutter 3.0. Could not find a file named "pubspec.yaml" in git://github.com/lyokone/google_map_location_picker.git 0206658d90352b7c6341fc44bb037e92968aba64. pub get failed (1; Could not find a file named "pubspec.yaml" in git://github.com/lyokone/google_map_location_picker.git 0206658d90352b7c6341fc44bb037e92968aba64.)

    opened by santhoshrao519 0
  • Additional google charges due to unused called method

    Additional google charges due to unused called method

    Results of these interesting methods are not used reverseGeocodeLatLng(latLng) getNearbyPlaces(latLng) So they should be desactivated as it creates addition unuseful search and consequently google additional charges

    opened by davemg3 1
  • Add support for Web thanks to Flutter Google map for web

    Add support for Web thanks to Flutter Google map for web

    Google map for flutter web just went out : https://pub.dev/packages/google_maps_flutter_web It should be possible now to add support for web. As the package is out of date, i am thinking about doing it myself : someone did start something?

    opened by davemg3 0
Owner
Ibrahim Eid
Mobile Developer (Flutter + Android). My Apps Apps: https://play.google.com/store/apps/developer?id=Humazed
Ibrahim Eid
Stateful map controller for Flutter Map

Map controller Stateful map controller for Flutter Map. Manage markers, lines and polygons. View the web demo Usage import 'dart:async'; import 'packa

null 55 Sep 15, 2022
Custom map markers - Custom Map Markers Using Flutter

Custom Map Markers Not only "Everything is a widget" also "Everywhere is a widge

null 8 Oct 19, 2022
Flutter Tutorial - Google Map with Live Location Tracking

Flutter Tutorial - Google Map with Live Location Tracking Build Google Map app with Live Location Tracking in Flutter. ✌   App Preview Android Preview

Samuel Adekunle 10 Dec 22, 2022
flutter_map plugin to request and display the users location and heading on the map

The plugin is discontinued. Feel free to fork it or checkout similar plugins. Flutter Map – Location plugin A flutter_map plugin to request and displa

Fabian Rosenthal 19 Oct 11, 2022
Flutter package to enable clustering of location markers on Google Maps using widgets specific to each location.

flutter_google_maps_widget_cluster_markers This widget implements a very specific adaptation of google_maps_cluster_manager, allowing different ,marke

Kek Tech 2 Jan 6, 2023
Map Picker for Flutter

Map Pin Picker A Vendor-free map Library for Easy and Quick Usage. Follow the steps to integrate Google Maps (https://pub.dev/packages/google_maps_flu

Akbar 16 Jul 15, 2022
Location picker for Flutter.

Flutter Place Picker The missing location picker made in Flutter for Flutter. With dark theme and custom localization support. ⚠️ Please note: This li

Degreat 143 Dec 6, 2022
A new flutter plugin for mapbox. You can use it for your map backgrounds inside flutter applications

A new flutter plugin for mapbox. You can use it for your map backgrounds inside flutter applications

Boris Gautier 5 Sep 14, 2022
A flutter package for select a city from svg map.

City Picker From Map A flutter package for select a city from svg map. Supported countries (+150) are here. Screenshots Getting Started In the pubspec

Ahmet ÇELİK 49 Nov 17, 2022
Flutter Google Map Example - Day 41

Flutter Google Map Example - Day 41 class Afgprogrammer extends Flutter100DaysOfCode { video() { return { "title": "Flutter Google Map Exa

Mohammad Rahmani 74 Jan 3, 2023
Flutter plugin to display a simple flat world map with animated points in real time

Flutter Simple Map Flutter plugin to display a simple flat world map with animated points in real time. Can be used as a presentation of online users,

Vladyslav Korniienko 7 Dec 8, 2022
A Flutter map widget inspired by Leaflet

flutter_map A Dart implementation of Leaflet for Flutter apps. Installation Add flutter_map to your pubspec: dependencies: flutter_map: any # or the

null 2.2k Dec 28, 2022
A map widget with live position updates for Flutter

Livemap A map widget with live position updates. Based on Flutter map and Geolocator. Provides a controller api to handle map state changes. Example i

null 45 Sep 28, 2022
Flutter Google Map Example

Flutter Google Map Example A Flutter application demonstrate google map. Preview Listener and Marker Compass MapTypes Plugin google_maps_flutter from

Bhavik Makwana 67 Sep 14, 2021
A Flutter package for place search using MapBox Api and for Static map image

About This package provides easy api calls to MapBox Search API. Also, it contains an static map image generator ?? . Maki Icons can be used now in ma

Ketan Choyal 63 Dec 2, 2022
How To Integrate Customized Google Map in Flutter

How To Integrate Customized Google Map in Flutter Let’s develop a customised Google Maps for the best user experience. Visit : https://medium.com/flut

Jaimil Patel 19 Dec 6, 2022
A Flutter map widget inspired by Leaflet

flutter_map A Dart implementation of Leaflet for Flutter apps. Usage Add flutter_map to your pubspec: dependencies: flutter_map: any # or the latest

AppTree Software, Inc 114 Dec 13, 2022
Flutter Aris Map Application

Flutter Aris Map Application Version 1️⃣ . 0️⃣ . 0️⃣ ➕ 1️⃣ 4️⃣ Getting Started $ git clone https://github.com/ariscybertech/aris_map.git $ flutter pac

Behruz Hurramov 4 Dec 22, 2022
A Flutter map widget inspired by Leaflet

flutter_map A Dart implementation of Leaflet for Flutter apps. Installation Add flutter_map to your pubspec: dependencies: flutter_map: any # or the

null 2.2k Jan 3, 2023