當我請求反向地理編碼時,我的 VALID 和 ENABLED Google API 密鑰正在從 Maps Geocoding API 生成 REQUEST_DENIED 回應。相同的 GOOGLE_API_KEY 與 Maps Static API 和 Maps SDK for Android API 在同一個專案上完美運行。是的,我已啟用地理編碼 API 進行計費。
我不明白為什么它不起作用,請幫助。
我的代碼:
static Future<String> getPlaceAddress(double lat, double lng) async {
final url = Uri.parse(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=$GOOGLE_API_KEY');
final response = await http.get(url);
return json.decode(response.body)['results'][0]['formatted_address'];
}
控制臺上的錯誤訊息:
Performing hot reload...
Syncing files to device sdk gphone x86...
Reloaded 1 of 960 libraries in 533ms.
D/MediaScannerConnection(10267): Scanned /data/user/0/com.example.dm_places/cache/d3bef27d-313a-4d37-8159-035faf606d438754135540374763487.jpg to null
D/EGL_emulation(10267): eglCreateContext: 0xf4525150: maj 2 min 0 rcv 2
I/flutter (10267): a
I/flutter (10267): File: '/data/user/0/com.example.dm_places/app_flutter/scaled_d3bef27d-313a-4d37-8159-035faf606d438754135540374763487.jpg'
I/flutter (10267): {error_message: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account, results: [], status: REQUEST_DENIED}
E/flutter (10267): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter (10267): #0 List.[] (dart:core-patch/growable_array.dart:260:36)
E/flutter (10267): #1 LocationHelper.getPlaceAddress (package:dm_places/helpers/location_helper.dart:19:49)
E/flutter (10267): <asynchronous suspension>
E/flutter (10267): #2 Places.addPlace (package:dm_places/providers/places.dart:21:21)
E/flutter (10267): <asynchronous suspension>
E/flutter (10267):
uj5u.com熱心網友回復:
錯誤訊息表明您沒有在請求中使用 API 密鑰。好像是因為amp;在request里面所以key省略了最后的引數。洗掉它amp;,您的請求將起作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/412490.html
標籤:
上一篇:GoogleMapsAndroid中的kml檔案沒有影像顯示
下一篇:反應影像src未定義-AWSS3
