I am following along with the tutorial from the following link on using Google Maps API to create a search function to look for places on a map:
Medium.com flutter tutorial
Below is the code that I believe constitutes the core of the issue:
/**
* Retrieves the user's location
* NOTE: This pretty much does the same thing as _animateToUser,
* but I separated the two
*/
Future<LatLng> getUserLocation() async {
var currentLocation = <String, double>{};
final uLocation = LocationManager.Location();
try {
currentLocation = await uLocation.getLocation();
final lat = currentLocation["latitude"];
final lng = currentLocation["longitude"];
final center = LatLng(lat, lng);
return center;
} on Exception {
currentLocation = null;
return null;
}
}
/**
* Searches for locations using Google Maps API
*/
Future<void> _search() async {
try {
final center = await getUserLocation();
Prediction p = await PlacesAutocomplete.show(
context: context,
strictbounds: center == null ? false : true,
apiKey: kGoogleApiKey,
onError: onError,
mode: Mode.overlay,
language: "en",
location: center == null
? null
: Location(center.latitude, center.longitude),
radius: center == null ? null : 10000);
showDetailPlace(p.placeId);
} catch (e) {
return;
}
}
/**
* Shows details of a place
*/
Future<Null> showDetailPlace(String placeId) async {
if (placeId != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
PlaceDetailWidget(placeId)),
);
}
} /**
* Retrieves the user's location
* NOTE: This pretty much does the same thing as _animateToUser,
* but I separated the two
*/
Future<LatLng> getUserLocation() async {
var currentLocation = <String, double>{};
final uLocation = LocationManager.Location();
try {
currentLocation = await uLocation.getLocation();
final lat = currentLocation["latitude"];
final lng = currentLocation["longitude"];
final center = LatLng(lat, lng);
return center;
} on Exception {
currentLocation = null;
return null;
}
}`
The problem is that, no matter what I type into the search bar, it will not autocomplete/suggest anything.
Example:
In this example I want to bring up a list of places that have the word grand in them like 'Grand Central Station', for instance.
Look in the console for errors. In my case, my billing was linked and relevent APIs was enabled, still it never show predictions. Then I added the following strictBounds & types as non-null values.
Prediction p = await PlacesAutocomplete.show(
context: context,
apiKey: Local.googleMapsAPIKey,
radius: 10000000,
types: [],
strictbounds: false,
mode: Mode.overlay,
language: "fr",
decoration: InputDecoration(
hintText: 'Search',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
color: Colors.white,
),
),
),
components: [Component(Component.country, "fr")],
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With