Bug 53023 - PlayServices Place Picker on Android doesn't search locally
Summary: PlayServices Place Picker on Android doesn't search locally
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
Depends on:
Reported: 2017-03-03 17:07 UTC by Philipp Sumi
Modified: 2017-04-12 21:22 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Comparison Android/iOS (314.04 KB, image/jpeg)
2017-03-13 09:07 UTC, Philipp Sumi
Sample app (not working) (43.93 KB, application/x-zip-compressed)
2017-04-10 15:03 UTC, Philipp Sumi

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Philipp Sumi 2017-03-03 17:07:39 UTC
Unlike on iOS, when using the place picker in the Play Services package (42.1001.0), searching by text input doesn't perform a local search, which makes the feature (and thus the place picker) completely useless. This has show stopper quality, unfortunately :/

I can observe this on Android only, iOS is fine.


* Open the place picker with predefined bounds (e.g. London)
* The map shows up correctly
* Enter some characters to search for something nearby
* The suggestions are total bogus, since no local search prioritization is being performed. (On iOS, it would immediately suggest the nearby location)
Comment 1 Philipp Sumi 2017-03-13 09:07:13 UTC
Created attachment 20285 [details]
Comparison Android/iOS

The screenshot shows the app on iOS and Android. Android displays suggestions from all over the globe, while the iOS version correctly suggests local places only that actually make sense.
Comment 2 Philipp Sumi 2017-04-04 07:37:46 UTC
Comment 3 Jimmy [MSFT] 2017-04-04 15:03:28 UTC
Hey Philipp, the place picker is part of Play Services, not Forms, so this would be better handled by the components team.
Comment 4 Jon Dick 2017-04-06 13:57:22 UTC
I'm afraid there's probably not much we can do on this one, we just bind the Places picker in the Play Services java library, so if Google chooses to implement it this way, our hands are tied.

Having said that, i'd be interested to see the code you're using to perform this search and see if there's any suggestions we could give.
Comment 5 Philipp Sumi 2017-04-06 20:51:37 UTC
I'm not convinced this is Google - their PlacePicker is being used so widely, there would be tons and tons of complaints on Stack Overflow. I also posted on S/O myself, and other Android (not Xamarin) devs didn't have the issue (search results were local as you would expect). OTOH, given that their API doesn't have too much to offer, I wouldn't know where I or the framework code could have gone wrong.

Here's my code. Not too much happening here - the map zooms in nicely where I want it, it's really just the search box that messes up.

        protected override void ShowPicker(PositionDto position, bool zoomLocal)
            //wider search radius for destination
            double offset = zoomLocal ? 0.001 : 0.03;

            var northEast = new LatLng(position.Latitude + offset, position.Longitude + offset);
            var southWest = new LatLng(position.Latitude - offset, position.Longitude - offset);
            var bounds = new LatLngBounds(southWest, northEast);

            var builder = new PlacePicker.IntentBuilder();
            builder = builder.SetLatLngBounds(bounds);

            Activity a = (Activity) context;
            var intent = builder.Build(a);
            a.StartActivityForResult(intent, PlacePickerRequestCode);
Comment 6 Philipp Sumi 2017-04-06 21:06:37 UTC
(btw, it's also be noteworthy, that their Places autocompletion API does support local suggestions out of the box, so that wouldn't be an exotic feature). I didn't use the place picker on my initial UI due to the Xamarin Forms limitations (stuck at and used that API myself. Right now, it's as if the map code would use the boundaries specified, while the autocompletion API calls wouldn't.
Comment 7 Jon Dick 2017-04-06 21:42:40 UTC
Do you have your GEO_API key specified in your metadata?

[assembly: MetaData ("com.google.android.geo.API_KEY", Value="your_key")]
Comment 8 Jon Dick 2017-04-07 00:49:50 UTC
I could reproduce the behaviour you were seeing, and then correct it by adding the proper metadata info as suggested in my previous comment.  I'm pretty confident this is the issue.
Comment 9 Philipp Sumi 2017-04-07 07:39:19 UTC

Thanks for investing the time, I really appreciate it. I'm super excited about your repro, but it didn't do it for me :/

My understanding of the PlacePicker is that it simply doesn't work without a key. I did a few tests with those now:

* I already had an API key in my manifest file.
* Removing the key causes the PlacePicker to immediately abort after opening it.
* Replacing it with an invalid key (the one I used for iOS) also broke the component.
* Replacing it with a new unrestricted key got me back to the old behavior (starts, but no local search).
* Removing the declaration from the manifest file, and using the Assembly-level attribute as you posted instead didn't change the behavior.

I noticed that for iOS, I am registering the key twice. Shouldn't be similar in Android, but who knows:

Google.Maps.MapServices.ProvideAPIKey("AIza_MyKey");           Google.Maps.PlacesClient.ProvideApiKey("AIza_MyKey");

Could you elaborate a bit on your repro please?
Comment 10 Jon Dick 2017-04-07 11:21:15 UTC
Sure, I haven't done anything particularly different than the code you showed me.

Here is the code I'm using: 

I am using 42.1001.0 of Google Play Services and 25.1.0 of Android Support libraries, so perhaps that's something to try.

The last thing I can think of is maybe your target device doesn't have Google Play Services (or a new enough version of it) installed?
Comment 11 Philipp Sumi 2017-04-07 16:37:33 UTC
Weird, I have the same issue with your sample - both on my Galaxy S6 and the emulator. You mentioned the key and I wonder whether something's wrong there: How could you reproduce the issue and then fix it? I guess you must have specified some sort of key in order to run the place picker in the first place, not?

I'll try to run a build on a different machine tonight and will post back on that, too.
Comment 12 Jon Dick 2017-04-07 17:32:37 UTC
Have you enabled the Android Places API for your key in the Google Developer Console?

I did not originally specify the `com.google.android.geo.API_KEY` metadata at all.  This is what made things work as you were reporting (no places showing up).  Once I created a key, for my app's keystore (in this case my debug .keystore) and enabled the Android Places API for android in the Google Developer Console it all started working...
Comment 13 Philipp Sumi 2017-04-10 15:01:28 UTC
Ok, this is driving me crazy. I ran your example with an adjusted key, and it still didn't work. Then built it on an indipendent machine and it still didn't work. Tried on both physical phone and simulator. I'm attaching now a complete project - if that one does work on your machine, but it doesn't on any of mine, this might be a culture setting causing the issue.

I also created a new Google project for this one, that has an independent key.

Thanks for bearing with me!
Comment 14 Philipp Sumi 2017-04-10 15:03:44 UTC
Created attachment 21406 [details]
Sample app (not working)

Sample app with an unrestricted Google key (Places API for Android enabled in the Google console).
Comment 15 Jon Dick 2017-04-10 17:04:22 UTC
Hey Philipp, just tried your code... No changes, just built and ran on emulator, and it works fine here:


Not sure what else to say, I think if there is a bug here, it's Google's bug and not an issue with the binding.
Comment 16 Philipp Sumi 2017-04-10 19:38:57 UTC
So just to be sure (because I'm also getting the map you posted in your screenshot): When you started entering text, all the suggested locations were in Switzerland?
Comment 17 Jon Dick 2017-04-10 20:18:50 UTC
Maybe I'm not sure what you mean exactly.

When i first launch the Intent, I see a list of suggested places "Near" me in the bottom part of the picker.  

If I go and start typing in the search box, it doesn't really seem to care about or favour places "Near" me.  Perhaps this is what you mean?

As a test, I created the same code in a java Android app and I see the exact same behaviour.  I get nearby suggestions on the main picker screen, and when I go to search, it doesn't prioritize places near me - for example if I type 'c' I see California, Colorado, Chicago, Mexico City as items in the list.  As far as I can tell, the Search box is not meant (at least on Android) to prioritize based on your location.

Again, the Xamarin and Java Android apps are working identically in this respect for me.
Comment 18 Philipp Sumi 2017-04-12 09:30:55 UTC
This is super weird - why would Google implement something like this, when the auto completion API also expects the same bounds parameter as the actual map? It's working as suspected on iOS (see my initial screnshot). Also, there's no posts about this on the net, so I'm still thinking something's wrong. After all, the search textbox is useless like this. Did you use my key for your Android Java sample by any chance?
Comment 19 Jon Dick 2017-04-12 18:05:30 UTC
I tried my own API key as well as yours in the java android project.

Sorry but I think this is how the library works.  In any case I'm quite confident if there is an issue it doesn't have anything to do with the binding since it's exactly the same in a Java app.  

Finally, when I search for something specific (let's say Colasanti's which is a location near me), it does show it in the list after I type just "Colas", so it seems like it's doing _some_ sort of intelligent searching near you, just not searching _only_ near you.

I'm going to mark this as resolved for now.  If there's any new info you find, please feel free to comment back and we can reopen.
Comment 20 Philipp Sumi 2017-04-12 21:22:49 UTC
Ok, I'll have to report this with Google then. Would you mind sharing your Java project with me so that I can submit a repro along with the bug report? I don't think they'll be willing to look into my Xamarin implementation :)