我正在使用Google的JAVA客户端API来获取路线,我正在发送这样的请求,
DirectionsRoute[] routes = DirectionsApi.newRequest(context)
.mode(TravelMode.DRIVING)
.origin(start).destination(end)
.waypoints(wayPoints).await();
答案 0 :(得分:1)
实际上我在那个请求之后犯了一个错误我得到了路由的结果但是它还包含了编码折线对象,它由lat lang数组组成,一旦我们解码了那么我们将获得所有的点,这样我们可以正确地获得路线。 结果由路径数组组成,每个元素由腿数组成(两点之间的路径详细信息),每条腿由步骤组成,最后每一步都有编码折线,以便获得正确的latlang,你应该解码该折线并使用它。 / p>
答案 1 :(得分:0)
非常感谢,你帮助了我很多,我目前正在使用xamarin并使用这种方法解码折线。
public class NasilYapilir extends Fragment {
int index;
private CheckBox checkBox;
private CheckBox[] checkBoxes;
List<Reciep> reciepList = new ArrayList<>();
LinearLayout linearLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_nasil_yapilir, container, false);
index = getArguments().getInt(DetailViewPager.KEY_INDEX_TAG);
linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout);
checkBoxes = new CheckBox[reciepList.size()];
load_data(index);
//populateDirections(reciepList,linearLayout);
Log.i("we are in nasil yaplir",index + "");
return view;
}
public void populateDirections(List<Reciep> reciep, ViewGroup container){
int i = 0;
for(Reciep recieps : reciep){
checkBoxes[i] = new CheckBox(getActivity());
// checkBoxes[i].setPadding(8,16,8,16);
checkBoxes[i].setText(recieps.getQuantity()+ " "+
recieps.getUnit_ad()+ " "+ recieps.getIngredients_ad());
reciep.size();
container.addView(checkBoxes[i]);
i++;
}
}
public void load_data(int index) {
task.execute("http://yemekapp.kuarkdijital.com.tr/v_recipe.php?id=" + index);
}
AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
URL url;
HttpURLConnection URLConnection = null;
String current = "";
try {
url = new URL(params[0]);
URLConnection = (HttpURLConnection) url.openConnection();
URLConnection.connect();
InputStream inputStream = URLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
int data = reader.read();
while (data != -1) {
current += (char) data;
data = reader.read();
}
}
catch (JSONException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return current;
}
@Override
protected void onPostExecute(String current) {
super.onPostExecute(current);
if(current.isEmpty())
return;
JSONObject itemObject = null;
JSONObject quantityObject = null;
JSONObject jsonObject = new JSONObject(current);
String item = jsonObject.getString("item");
JSONArray itemArray = new JSONArray(item);
for (int i = 0; i < itemArray.length(); i++) {
itemObject = itemArray.getJSONObject(i);
String itemsQuantity = itemObject.getString("items");
JSONArray quantityArray = new JSONArray(itemsQuantity);
for(int j = 0; j<quantityArray.length() ;j++){
quantityObject = quantityArray.getJSONObject(i);
Reciep reciep = new Reciep(quantityObject.getString("Quantity"),quantityObject.getString("unit_ad"),quantityObject.getString("ingredient_ad"));
reciepList.add(reciep);
Log.i("quatityArray",quantityArray.get(j).toString());
}
}
populateDirections(reciepList,linearLayout);
}
}
}