【问题标题】:URL manipulation for weather rest api天气休息 api 的 URL 操作
【发布时间】:2021-09-26 00:33:49
【问题描述】:

您好,我正在尝试根据当前位置找出如何更改城市。有没有办法可以操纵“{city}”?这可能是一个非常简单的问题。截至目前,我的应用程序知道设备位置,但我不知道如何操作 url。我应该使用不同的 API 吗?

interface ApiService {

    @GET("weather/{city}")
    suspend fun getWeather():Response<Weather> 
}

【问题讨论】:

    标签: kotlin geolocation retrofit rest weather-api


    【解决方案1】:

    您可以为此使用@Path

    例如:

    @GET("weather/{city}")
    suspend fun getWeather(@Path("city") val city: String):Response<Weather>
    

    现在,当您调用该函数时。传递字符串以动态更新“城市”。

    【讨论】:

      猜你喜欢
      • 2013-01-15
      • 2012-03-29
      • 1970-01-01
      • 2020-09-03
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      相关资源
      最近更新 更多