Android Retrofit + Google Places API(文本搜索)
我正在尝试根据给定的查询来获取地点。 我实现了以下接口。
@GET("api/place/textsearch/json?key=MY_API_KEY") Call<PlaceResponse> getNearbyPlacesByText(@Query("query") String query, @Query("location") String location, @Query("radius") int radius);
然后我这样调用这个方法
Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .addConverterFactory(GsonConverterFactory.create()) .build(); ApiInterface service = retrofit.create(ApiInterface.class); Call<PlaceResponse> callByText = service.getNearbyPlacesByText("psí" + "škola", currentLocation.getLatitude() + "," + currentLocation.getLongitude(), PROXIMITY_RADIUS);
然后我正在检索结果。
callByText.enqueue(new Callback<PlaceResponse>() { @Override public void onResponse(Call<PlaceResponse> call, Response<PlaceResponse> response) { List<Place> places = response.body().getResults(); Log.d(TAG, "Number of places received: " + places.size()); setMarkers(type, places, googleMap, context); } @Override public void onFailure(Call<PlaceResponse> call, Throwable t) { } });
但我得到更多的结果,不匹配给定的查询(我得到20个地方)。 我在邮递员的网址https://maps.googleapis.com/maps/api/place/textsearch/json?query=psí+škola&location=49.188963,16.532183&radius=50000&key=MY_KEY
我不确定是否在我的代码中正确设置了网址。
感谢任何意见,我只有8个地方是正确的数字。 我不确定我是否
- Lint在Java类上读取Kotlin对象时崩溃
- :运行单元测试时出现app:kaptDebugKotlin错误
- 消息没有收到蓝牙聊天。 我的处理程序是否坏了
- Android Studio 3.0会添加参数提示信息吗?
- 数据绑定Kotlin Android工作室错误
您可以在Retrofit中设置日志记录,并检查正在发送的内容(例如在Kotlin中)。
val logging = HttpLoggingInterceptor() logging.level = HttpLoggingInterceptor.Level.BODY val httpClient = OkHttpClient.Builder() httpClient.addInterceptor(logging) Retrofit.Builder() .baseUrl(url) .client(httpClient.build()) .build() .create(ApiDao::class.java)