在我的 flutter 应用程序中,我实现了 HERE Places API(HERE sdk)来根据给定的查询字符串(查询)和硬编码的地理位置搜索地点。但它给出了 403 状态代码。
Future<void> _searchPlaces(String query) async {
print('Searching for: $query');
final String apiKey =
'API_KEY&size=50&result_types=place';
final String baseUrl = 'https://places.ls.hereapi.com/places/v1/autosuggest';
final response = await http.get(
Uri.parse('$baseUrl?at=28.6925834,77.1526937&q=$query&apiKey=$apiKey'),
);
print('status code: ${response.statusCode}');
if (response.statusCode == 200) {
final Map<String, dynamic> data = json.decode(response.body);
setState(() {
_places = data['results'];
});
} else if (response.statusCode == 403) {
throw Exception(
'Failed to load places: Access forbidden. Check your API key or permissions.');
} else {
throw Exception('Failed to load places: ${response.statusCode}');
}
}
var baseUrl = 'https://places.ls.hereapi.com/places/v1/autosuggest?'; var jsonRequest=jsonEncode(at=28.6925834,77.1526937&q=$query&apiKey=$apiKey);
现在通过您的方法获得响应