martin-braun-net / google_maps_place_picker_mb

Place picker on Google Maps for Flutter
https://pub.dev/packages/google_maps_place_picker_mb
MIT License
33 stars 97 forks source link

Allow searching near-by #45

Closed martin-braun closed 1 year ago

martin-braun commented 1 year ago

If you travel abroad without changing your phone's locale, you will still see results from your home country. For example, my phone is set in British English, so my search only show results in the UK, no matter where I am at the moment.

A good workaround would be to authorize the use of:

PlacesSearchResponse response = await places.searchNearbyWithRankby(new Location(31.0424, 42.421), "distance"); which is available in the https://pub.dev/packages/google_maps_webservice package.

_Originally posted by @Dereumaux-Adrien in https://github.com/martin-braun/google_maps_place_picker_mb/issues/32#issuecomment-1384640201_

Maybe an option is to offer a flag that allows you to search near-by? I assume the issue with searchNearbyWithRankby is that you cannot find stuff far away, so it shall be optional.

_Originally posted by @martin-braun in https://github.com/martin-braun/google_maps_place_picker_mb/issues/32#issuecomment-1385560033_

Dereumaux-Adrien commented 1 year ago

After looking more in details, I understood that using places.searchNearbyWithRankby would not work as it doesn't provide the same kind of output as the actually used places.autocomplete (respectively PlacesSearchResponse and PlacesAutocompleteResponse).

I also looked in the autocomplete documentation and found that there should be a way to make these with autocomplete as well, it mentions rankby=distance here but this one is weirdly not mentionned in the parameters. But the parameters' category locationbias seems to be offering many ways to control which results come first and are favored. These sadly don't seem to be readily available google_maps_service, they may have been added to places later on.

Not wanting to update all that by myself, I tried to "play" around with the values that are already available and sound alike.

I did some more digging and found that setting autocompleteRadius is a good temporary workaround not depending on the locale of the device. But it sadly doesn't order by proximity (For example autocompleteRadius:5000 will first give me results less than 5000m away, but the top one might not be the closest one).

And then I tried lowering the value to see what happens if the closest result is much further than my minimum radius. It seems that setting autocompleteRadius:5 orders the results by order of proximity and I guess that if many results are present less than 5 meters away from the user, they can be ordered in any way without it impacting the user.

I think that the most important at the moment is to add in the documentation that autocompleteRadius can be used to order the results by proximity. If you still want to add the locationbias (as I am not sure if rankby=distance is really possible) I could maybe guide you in the process for the google_maps_service side (I think I understood where the changes are needed).

martin-braun commented 1 year ago

@Dereumaux-Adrien Thanks for your analysis and great work so far, it helps to find the shortcut, as I'm currently rather maintaining than enhancing this library due to time constraints. autocompleteRadius seems to be sufficient for the problem and I think the caveat in regards of the lack of proximity ordering for the specified radius is not even a problem and rather a feature.

If I have a radius of 5km that I'm accepting to travel for the best destination, I want the best/largest/most known location of my search within that radius, not the closest one. If I want to travel the least possible, autocompleteRadius:1 should be the way to go. autocompleteRadius:1 should then still give results ordered by range outside of such radius, if I understand you correctly.

If you feel confident, I would highly appreciate if you could update the README to document the property properly. Otherwise I will update it later myself.

Thanks again, brother.