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个地方是正确的数字。 我不确定我是否
您可以在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)
- 在kotlin中使用Gson来解析json数组
- 是否有可能将kotlin中的高阶函数映射到字符串
- 格式@Query参数 – 改造2
- 如何将MotionEvent停机时间与时钟进行比较,时间基准是多少?
- 使用Espresso的Android仪器测试失败:NoSuchMethodError javax.inject.Provider中的get()
- Kotlin:如何使用扩展功能延迟运行一个函数
- 在房间中更改Flowable <List <Obj1 >>为Flowable <List <Obj2 >>
- Android Studio中的Kotlin Room安装问题
- 当CollapsingToolbarLayout展开时,使菜单项透明