mapbox / mapbox-plugins-android

Mapbox Android Plugins are a collection of libraries that extend our other SDKs, helping you design powerful mapping features while the plugins handle most of the heavy lifting.
https://www.mapbox.com/android-docs/plugins/overview/
BSD 2-Clause "Simplified" License
241 stars 120 forks source link

Autocomplete results stop showing #1008

Open jollygreenegiant opened 5 years ago

jollygreenegiant commented 5 years ago

I'm using the Autocomplete UI component using launchActivityForResult() with the following code:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        if (item.getItemId() == R.id.search_button) {

            // Start the autocomplete intent.
            Intent intent = new PlaceAutocomplete.IntentBuilder()
                    .accessToken(Mapbox.getAccessToken())
                    .placeOptions(PlaceOptions.builder()
                            .language(Locale.getDefault().getLanguage())
                            .backgroundColor(Color.parseColor("#EEEEEE"))
                            .build(PlaceOptions.MODE_CARDS))
                    .build(getActivity());
            startActivityForResult(intent, 1);
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                CarmenFeature feature = PlaceAutocomplete.getPlace(data);
                initializeWeatherData(feature.center().latitude(), feature.center().longitude());
            }
        }
    }

When the app is first installed, everything is fine, and it seems to work the first several times, but after a while (or maybe a certain number of searches?) it stops returning any results, either while typing or after clicking the search button. Is this an issue with the API or something I've written? I assume it's in my code, but I don't know how to debug it and view the calls and responses. Gif of behavior is attached below, running on Google Pixel 3XL, Android Q (API 29).

I have tested on multiple Wi-Fi networks, as well as mobile data, with no luck. Once it stops working, it doesn't come back until I uninstall and reinstall the app.

ezgif com-video-to-gif

langsmith commented 5 years ago

hey @jollygreenegiant . Thanks for using Mapbox. What version of the Places Plugin are you using? If you're not using the latest version, 0.9.0, please try it. I ask because the latest version addressed https://github.com/mapbox/mapbox-plugins-android/issues/982 and https://github.com/mapbox/mapbox-plugins-android/issues/976.

Also, are you seeing any crashes/errors/warnings in your logcat when the results stop arriving? Anything as you type?

jollygreenegiant commented 5 years ago

Thanks for responding so quick! I am using 0.9.0, using implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v8:0.9.0'

There is no notable output when using the Autocomplete UI, even on Verbose. Almost no output at all actually

jollygreenegiant commented 5 years ago

My source code is here if you'd like to try it out: https://github.com/jollygreenegiant/SimpleWeather

It may be difficult to reproduce though, since it seems to work fine at the start. At one point, I had a call to .limit(10) in the placeOptions builder, and it looked like once it hit that limit, it stopped giving suggestions and searching, but I have since removed that call.

I just did a clean install of the app, and it actually didn't work the first try, so maybe downloading the source code for my app may be useful.

jollygreenegiant commented 5 years ago

@langsmith any updates on this? Is there a way I can view the API responses so I can try to debug what's going on?

langsmith commented 5 years ago

Haven't had any time to dive into this since we "chatted" yesterday. I got a Dark Sky key and used my personal google cloud engine to get a places API key. I've got your app up and running. Results don't even show up for me once.

I thought that maybe things weren't working for you because our plugin('s PlaceAutocompleteActivity, PlaceAutocompleteFragment, and other downstream code) isn't/aren't compatible with AndroidX 😕 But your android.enableJetifier=true usage should handle that, I believe.

Screen Shot 2019-07-10 at 10 56 21 PM Screen Shot 2019-07-10 at 10 57 55 PM

Unfortunately, there's no real easy way to see the API response that I know of. Would have to happen on the plugin side 😕

When I click on the magnifying glass to open Mapbox search, I get 2019-07-10 23:07:01.242 3359-3359/com.jggdevelopment.simpleweather E/t.simpleweathe: No package ID ff found for ID 0xffffffff.

Screen Shot 2019-07-10 at 11 05 39 PM

I used the plugin test app to test your PlaceAutocomplete.IntentBuilder() parameters. I can confirm that the work in the plugin test app's AutocompleteLauncherActivity. Could be interesting to use Android Studio to auto-convert the test app to AndroidX to see if AutocompleteLauncherActivity.

What's weird is that it stops working, rather than not working at all. The fact that it works originally, makes me think that all of this AndroidX package stuff is moot.

jollygreenegiant commented 5 years ago

Thanks for taking the time to get the API keys and everything to actually take a look at it, I really appreciate it.

So I removed the constraintLayout dependency from gradle (the one that was giving the no packge ID error), updated AndroidX to the newest RC build from the beta, and now everything looks great. That said, it looked great before too, and then it stopped working, so I'm not sure how it will hold up, but for now everything looks good.

One last question, while I have you. Is there a way to make the search field focused when the autocomplete activity is launched so that they keyboard automatically comes up, rather than the user having to click in the box first?

langsmith commented 5 years ago

Thanks for taking the time to get the API keys and everything to actually take a look at it

You're welcome

That said, it looked great before too, and then it stopped working, so I'm not sure how it will hold up, but for now everything looks good.

Yeaaa, we'll see. If you push your changes, perhaps I can try them out on my end to see whether the results appear for me at least once, if not continually time after time.

Is there a way to make the search field focused when the autocomplete activity is launched so that they keyboard automatically comes up, rather than the user having to click in the box first

No, that's not currently part of the plugin, but it doesn't seem particularly hard to implement.

https://stackoverflow.com/questions/8991522/how-can-i-set-the-focus-and-display-the-keyboard-on-my-edittext-programmatical

Ticketed at https://github.com/mapbox/mapbox-plugins-android/issues/1011 so that it's remembered.

jollygreenegiant commented 5 years ago

The updated code has been pushed, if you want to check it out at any point.

I know how to set the focus for an EditText, I assumed that was how it would be done, but how can I access that EditText of that view, since it's being launched with the IntentBuilder? It's not inflating a layout of mine that I can grab a reference from, it's just whatever the default layout is that's included in the plugin.

ganny08 commented 5 years ago

Hello. I have this problem to. I copy PlacesPluginActivity from example, but search not work for me.

implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v8:0.9.0' All AndroidX lib was updated to latest version

ganny08 commented 5 years ago

I use implementation 'androidx.constraintlayout:constraintlayout:1.1.3' instead implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' and it work for me

dhavalp2511 commented 5 years ago

You can use PlaceAutocompleteFragment that working fine for me.

dhavalp2511 commented 5 years ago

I use implementation 'androidx.constraintlayout:constraintlayout:1.1.3' instead implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' and it work for me

This one also works for me

typebrook commented 5 years ago

I use implementation 'androidx.constraintlayout:constraintlayout:1.1.3' instead implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' and it work for me

Looks like this solution cannot apply to fragment with AndroidX Navigation