Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android上的Google Api_Android_Json_Retrofit_Elevation - Fatal编程技术网

使用Android上的Google 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

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

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();//用于同步响应