【发布时间】:2020-01-18 10:38:25
【问题描述】:
我有一个如下所示的网址。
https://maps.googleapis.com/maps/api/geocode/json?key=MY-KEY-API&latlng=40.9927242,29.0231916
我想通过如下所示的改造部分从 url 获取 json 结果。
public static final String URL = "https://maps.googleapis.com";
@GET("/maps/api/geocode/json")
Call<Location> getInformation(@Query("latlng") String lat);
Call<Location> req = Manager.getInstance().getCity("40.9927242,29.0231916");
响应如下所示。
response : Response{protocol=h2, code=200, message=, url=https://maps.googleapis.com/maps/api/geocode/json?latlng=40.9927242%2C29.0231916}
API key 不能插入到 url 部分,即使它在 AndroidManifest.xml 中定义
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
google_maps_key.xml
<string name="google_maps_key"
templateMergeStrategy="preserve" translatable="false">
MY-KEY-API
</string>
当我点击url时,由于没有在url中添加API,错误以json格式定义。
{
"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"
}
我该如何解决?
【问题讨论】:
标签: android google-maps retrofit google-maps-android-api-2 google-geocoding-api