代码之家  ›  专栏  ›  技术社区  ›  FAYA

从Android使用Google Elevations Api

  •  2
  • FAYA  · 技术社区  · 8 年前

    我想获取包含给定纬度和经度高程的json文件(并提供api键)。我读了很多书,发现改型是Android中最好的选择,但我不知道如何指定参数。

    public interface ServiceApi {
    //url format
    //"https://maps.googleapis.com/maps/api/elevation/json?locations="
    // latitude+","+longitude+"&key="+key;
    @GET("")
    public void getJSON(Callback<List<JsonElevation>> jsonElevationCallback);
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Gary99    8 年前

    我没有Elevations API密钥来测试这一点,但使用的是改装的 documentation ,像这样的东西应该有用。

        @GET("/maps/api/elevation/json")
        public Call<List<JsonElevation>> getJSON(@Query("locations") String latAndLng,
                                                     @Query("key") String key);
    

    那么就称之为:

        Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://maps.googleapis.com/")
            .addConverterFactory(GsonConverterFactory.create(new Gson()))
            .build();
    
        ServiceApi serviceApi = retrofit.create(ServiceApi.class);
    
        String latAndLng = String.format("%f,%f", latitude, longitude);
        Call<List<JsonElevation>> elevations = serviceApi.getJSON(latAndLng, key);
    
        elevations.enqueue();  // for asychronous response          
        //or        
        elevations.execute();   // for synchronous response
    
    推荐文章