getPlaceId method
Implementation
Future<String?> getPlaceId(String input) async {
final String url =
'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=$input&inputtype=textquery&key=$key';
var response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
var json = convert.jsonDecode(response.body);
// Check if there are candidates in the response
if (json['candidates'] != null && json['candidates'].isNotEmpty) {
var placeId = json['candidates'][0]['place_id'] as String;
return placeId;
}
}
// Return null if there are no candidates or if there's an error
return null;
}