fysoul17 / google_maps_place_picker

Place picker on Google Maps for Flutter
MIT License
222 stars 357 forks source link

Autocomplete does not show results if search has trailing whitespace #54

Closed therladbsgh closed 3 years ago

therladbsgh commented 3 years ago

Describe the bug The autocomplete section will not show any results if there is trailing whitespace at the end of the query.

To Reproduce Steps to reproduce the behavior:

  1. Open a PlacePicker() widget
  2. Type any text with trailing whitespace, e.g. "san francisco " (note the space at the end)
  3. See the lack of results
  4. Remove the space at the end
  5. See that results have now appeared

Expected behavior Results should appear.

Screenshots Below is an example of searching with no trailing whitespace (autocomplete shows promptly): VibrantFlamboyantGelding-size_restricted

Below is an example of searching with trailing whitespace (autocomplete will not show, until the whitespace is removed):

WithWhitespace

Flutter Doctor -v

[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F96, locale en)
    • Flutter version 1.17.5 at /Users/_/Documents/flutter
    • Framework revision 8af6b2f038 (4 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/_/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.47.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.0

[✓] Connected device (2 available)
    • SM G970U1         • 192.168.1.235:5555                   • android-arm64 • Android 10 (API 29)
    • iPhone 11 Pro Max • C8C35BF3-1652-4614-82CF-24B828296F20 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-5 (simulator)

• No issues found!

Additional context Probably solvable by doing .trim() on the search term before using the Maps API?

PlacePicker usage:

PlacePicker(
        hintText: "Search for a location...",
        apiKey: "_",
        onPlacePicked: (result) {
          print(result.formattedAddress);
          print(result.geometry.location);
          Navigator.of(context).pop();
        },
        initialPosition: LatLng(10, 10),
        useCurrentLocation: false,
      ),
therladbsgh commented 3 years ago

So, observing autocomplete_search.dart, this seems to be an intentional decision:

if (controller.text.substring(controller.text.length - 1) == " ") {
      provider.debounceTimer?.cancel();
      return;
    }

But I'm not sure what the rationale behind this would be -- most other applications with a map search will show results regardless of the space at the end.

fysoul17 commented 3 years ago

One of the main reasons I made the package is to minimize the API call if possible. There are several packages (actually I found one similar to this) that provides place picking, but I noticed that there are too many unnecessary API calls which may charge me a lot of money for using the google map API. (It is quite expensive compare to other APIs)

So, you may see several other things that I put to reduce as fewer API calls as possible, like 'debounce timer', 'not performing a search when only zoom has changed', etc.. And yes, the code you found is also an intentional decision as typing whitespace (pressing space bar) means the user has an intention to type next word which means we don't need to waste API call until the user finishes typing the words.

Well, that was my basic intentions and of course, it is fair enough to say we need to provide search results whenever a user types a word in terms of UX. I will think about providing an optional parameter to skip the 'if statement' if there are more people who want this function.

Thanks for your opinion @therladbsgh.

fysoul17 commented 3 years ago

Closing as the issue has been solved.