我正在尝试使用Retrofit向Google GeoCode API发送请求。服务界面如下所示:
public interface FooService {
@GET("/maps/api/geocode/json?address={zipcode}&sensor=false")
void getPositionByZip(@Path("zipcode") int zipcode, Callback<String> cb);
}
当我致电服务时:
OkHttpClient okHttpClient = new OkHttpClient();
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Constants.GOOGLE_GEOCODE_URL).setClient(new OkClient(okHttpClient)).build();
FooService service = restAdapter.create(FooService.class);
service.getPositionByZip(zipCode, new Callback<String>() {
@Override public void success(String jsonResponse, Response response) {
...
}
@Override public void failure(RetrofitError retrofitError) {
}
});
我收到以下堆栈跟踪:
06-07 13:18:55.337: E/AndroidRuntime(3756): FATAL EXCEPTION: Retrofit-Idle
06-07 13:18:55.337: E/AndroidRuntime(3756): Process: com.marketplacehomes, PID: 3756
06-07 13:18:55.337: E/AndroidRuntime(3756): java.lang.IllegalArgumentException: FooService.getPositionByZip: URL query string "address={zipcode}&sensor=false" must not have replace block.
06-07 13:18:55.337: E/AndroidRuntime(3756): at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:120)
06-07 13:18:55.337: E/AndroidRuntime(3756): at retrofit.RestMethodInfo.parsePath(RestMethodInfo.java:216)
06-07 13:18:55.337: E/AndroidRuntime(3756): at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:162)
06-07 13:18:55.337: E/AndroidRuntime(3756): at
我看了一下StackOverflow问题:改进:@GET命令中有多个查询参数?但它似乎不适用。
我从这里逐字逐句地获取了代码:http : //square.github.io/retrofit/,所以对于理解这个问题我有些茫然。
有什么想法吗?