3
Googleのapiからの応答を受信した後、どのように地図上に駆動道路を表示することができますか?ストリートビューに切り替えるにはどうすればよいですか? 。ここgoogle direction apiからの応答を受け取った後、
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=AIzaSyBX40zJvRu0PBVs5iA0xG_cmdpVAUKYmmQ";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
Log.e("Response is: ", response.toString());
////////////////json response //////////
try {
String responseString;
JSONObject responseObject = (JSONObject) new JSONTokener(response.toString()).nextValue();
responseString = responseObject.getString("status");
JSONArray routesArray = responseObject.getJSONArray("routes");
JSONObject route = routesArray.getJSONObject(0);
JSONArray legs;
JSONObject leg;
JSONArray steps;
JSONObject dist;
Integer distance;
if (route.has("legs")) {
legs = route.getJSONArray("legs");
leg = legs.getJSONObject(0);
steps = leg.getJSONArray("steps");
int nsteps = steps.length();
for (int i = 0; i < nsteps; i++) {
JSONObject step = steps.getJSONObject(i);
if (step.has("distance")) {
dist = (JSONObject) step.get("distance");
if (dist.has("value"))
distance = (Integer) dist.get("value");
}
}
} else
responseString = "not found";
} catch (Exception e) {
e.printStackTrace();
}
////////////////////////////
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Response is: ", "error");
}
});
は応答です:
{
"geocoded_waypoints":[
{
"geocoder_status":"OK",
"place_id":"ChIJRVY_etDX3IARGYLVpoq7f68",
"types":[
"bus_station",
"establishment",
"point_of_interest",
"transit_station"
]
},
{
"geocoder_status":"OK",
"partial_match":true,
"place_id":"ChIJE0RfH0m-woAROpQUDVXcp1A",
"types":[
"route"
]
}
],
"routes":[
{
"bounds":{
"northeast":{
"lat":34.1380726,
"lng":-117.9143879
},
"southwest":{
"lat":33.8068768,
"lng":-118.3545268
}
},
"copyrights":"Map data ©2016 Google",
"legs":[
{
"distance":{
"text":"36.5 mi",
"value":58724
},
"duration":{
"text":"53 mins",
"value":3192
},
"end_address":"Studio way, North Hollywood, CA 91602, USA",
"end_location":{
"lat":34.1378505,
"lng":-118.3545268
},
"start_address":"Disneyland (Harbor Blvd.), S Harbor Blvd, Anaheim, CA 92802, USA",
"start_location":{
"lat":33.8098177,
"lng":-117.9154353
},
"steps":[
{
"distance":{
"text":"0.2 mi",
"value":310
},
"duration":{
"text":"1 min",
"value":79
},
"end_location":{
"lat":33.8070347,
"lng":-117.9154133
},
"html_instructions":"Head \u003cb\u003esouth\u003c/b\u003e on \u003cb\u003eS Harbor Blvd\u003c/b\u003e",
"polyline":{
"points":"[email protected]@Z?RALA`@[email protected]"
},
"start_location":{
"lat":33.8098177,
"lng":-117.9154353
},
"travel_mode":"DRIVING"
},
{
"distance":{
"text":"0.6 mi",
"value":1039
},
"duration":{
"text":"3 mins",
"value":195
},
"end_location":{
"lat":33.8159247,
"lng":-117.9152992
},
"html_instructions":"Make a \u003cb\u003eU-turn\u003c/b\u003e at \u003cb\u003eDisney Way\u003c/b\u003e",
"maneuver":"uturn-left",
"polyline":{
"points":"}|imEhjunU\\[email protected]]@[email protected][email protected]{@[email protected][email protected][email protected][email protected]?M?O?IAE?I?O?][email protected]?{@@[email protected]"
},
"start_location":{
"lat":33.8070347,
"lng":-117.9154133
},
"travel_mode":"DRIVING"
},
{
"distance":{
"text":"22.9 mi",
"value":36928
},
"duration":{
"text":"27 mins",
"value":1593
},
"end_location":{
"lat":34.0255711,
"lng":-118.2060101
},
"html_instructions":" Take the ramp onto \u003cb\u003eI-5 N\u003c/b\u0