使用Android上的Google Api
我想获取包含给定纬度和经度的高程的json文件(并提供api键)。我读了很多书,发现改型是安卓系统的最佳选择,但我不知道如何指定参数使用Android上的Google Api,android,json,retrofit,elevation,Android,Json,Retrofit,Elevation,我想获取包含给定纬度和经度的高程的json文件(并提供api键)。我读了很多书,发现改型是安卓系统的最佳选择,但我不知道如何指定参数 public interface ServiceApi { //url format //"https://maps.googleapis.com/maps/api/elevation/json?locations=" // latitude+","+longitude+"&key="+key; @GET("") public void getJSON(C
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);
}
公共接口服务API{
//url格式
//"https://maps.googleapis.com/maps/api/elevation/json?locations="
//纬度+”、“+经度+”&key=“+key;
@得到(“”)
public void getJSON(回调jsonElevationCallback);
}
我没有API密钥来测试这一点,但使用改型,类似的东西应该可以工作
@GET("/maps/api/elevation/json")
public Call<List<JsonElevation>> getJSON(@Query("locations") String latAndLng,
@Query("key") String key);
@GET(“/maps/api/elevation/json”)
公共调用getJSON(@Query(“locations”)字符串latAndLng,
@查询(“键”)字符串键);
那么就称之为:
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
reformation-reformation=new-reformation.Builder()
.baseUrl(“https://maps.googleapis.com/")
.addConverterFactory(GsonConverterFactory.create(new Gson()))
.build();
ServiceApi ServiceApi=reformation.create(ServiceApi.class);
String latAndLng=String.format(“%f,%f”,纬度,经度);
调用elevations=serviceApi.getJSON(latAndLng,key);
立面图。enqueue();//对于非同步响应
//或
elevations.execute();//用于同步响应