【发布时间】:2020-11-23 10:29:21
【问题描述】:
我在一个 android 项目中使用改造,以便能够调用 google maps api 并获得地点的自动完成建议。我正在为调用传递一个地址(字符串参数类型)。 RetrofitCaller 类的 start 方法如下所示:
private val BASE_URL = "https://maps.googleapis.com/maps/"
fun start(address: String) {
val gson = GsonBuilder()
.setLenient()
.create()
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
val placeAutoCompleteAPI: PlaceAutoCompleteAPI =
retrofit.create(PlaceAutoCompleteAPI::class.java)
val call: Call<PredictionResponse?>? = placeAutoCompleteAPI.loadPredictions(address)
call?.enqueue(this)
}
PlacesAutoCompleteApi 具有带有 loadPredictions 函数的 http 请求:
@GET("api/place/autocomplete/json?types=address&key=AIzaSyApUcl88FpB4xHH0HS9FW4WC4wHaJu3VVU")
fun loadPredictions(@Query("input") address: String?): Call<PredictionResponse?>?
但是我无法从服务器获得响应。我对从服务器查询返回的数据类型使用 PredictionResponse 和 Prediction 类。
代码或方法有什么问题?
提前谢谢你, 兰普罗斯
【问题讨论】:
-
你为什么不使用Android SDK?
标签: android api kotlin maps retrofit