我想创建
GET
请求此API:
http://maps.googleapis.com/maps/api/geocode/json?latlng=myLatitude,myLongitude&sensor=true
而不是
myLatitude
和
myLongitude
,我需要把我自己的价值观。下面您可以看到我是如何尝试使用改装完成请求的:
API接口:
@GET("json?latlng={lat},{long}&sensor=true")
Call<JsonArray> getApproximateLocations(@Query(value = "lat" , encoded = true) String lat, @Query(value = "long" , encoded = true) String lon);
我的请求:
Retrofit retrofit = new Retrofit.Builder().baseUrl(getString(R.string.location_base_api)).addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface apiInterface = retrofit.create(ApiInterface.class) ;
mapsApiInterface.getApproximateLocations(String.valueOf(lat),String.valueOf(lon)).enqueue(new Callback<JsonArray>() {
@Override
public void onResponse(Call<JsonArray> call, Response<JsonArray> response) {
}
@Override
public void onFailure(Call<JsonArray> call, Throwable throwable) {
}
});
我的基本URL是:
http://maps.googleapis.com/maps/api/geocode/
.
此代码的结果是以下错误:
java.lang.IllegalArgumentException: URL query string "latlng={lat},{long}&sensor=true" must not have replace block. For dynamic query parameters use @Query.
那么,我为什么会出现这个错误以及如何解决这个问题呢?