Currently, I am working on a restaurant app where people can take photos and tag them to a Google Place. However, since my app is targeting developing countries like India, the Google Places are not all very well defined. So I am allowing users to search for a place which they think more accurately reflects the location of their favourite restaurant.
I am using PlaceAutocompleteFragment
fragment of Google Places API for android as input mechanism for users to search for their favourite joint. However, to make it easier for them to choose, I want to bias results towards a specific region - more specifically the city that they are performing the search from.
However, how do I get get city of the current location of the user? I can get latitudes, longitudes. But how do I retrieve the city corresponding to a certain lat and long?
Do I need to reverse geocode the address from lat, long to get address? But if I do that, then how do I reliably get a city name? And thereafter what would be the correct provision in the PlaceAutocompleteFragment to set a 'city' filter?
So what would be the easiest way to do it? Any ideas? Appreciate it.
autocompleteFragment.setBoundsBias(new LatLngBounds(southwestLatLng, northeastLatLng));
setBoundsBias()
takes a LatLngBounds
which is made up of two LatLng
objects representing the southwest and northeast points of a bounding rectangle. The Google APIs don't appear to provide a method of getting a city's bounds, so you will have to figure out what is an acceptable radius to search within and subtract/add from the user's current latitude and longitude to derive the two points of the bounding rectangle. See: Calculating bounding box a certain distance away from a lat/long coordinate in Java