URI for Google Maps Intent with waypoints

六月ゝ 毕业季﹏ 提交于 2019-12-01 14:32:39

Thanks to @kaho, for this "I think you can use +to:waypoint after the destination address."

This works for me with multiple way points:

  RealmList<LocationEntity> list = routeEntity.getStops();
  ArrayList<Map<String,Object>> latLang = new ArrayList<>();

  for (LocationEntity location: list){
    latLang.add(location.toMap());
  }


  String jsonURL = "https://maps.google.com/maps?";
  final StringBuffer sBuf = new StringBuffer(jsonURL);
  sBuf.append("saddr=");
  sBuf.append(destLat);
  sBuf.append(',');
  sBuf.append(destLong);
  sBuf.append("&daddr=");
  sBuf.append(sourceLat);
  sBuf.append(',');
  sBuf.append(sourceLong);
  sBuf.append("+to:");
  sBuf.append(latLang.get(0).get("latitude"));
  sBuf.append(',');
  sBuf.append(latLang.get(0).get("longitude"));
  sBuf.append("+to:");
  sBuf.append(latLang.get(1).get("latitude"));
  sBuf.append(',');
  sBuf.append(latLang.get(1).get("longitude"));
  sBuf.append("+to:");
  sBuf.append(latLang.get(2).get("latitude"));
  sBuf.append(',');
  sBuf.append(latLang.get(2).get("longitude"));
  sBuf.append("+to:");
  sBuf.append(latLang.get(3).get("latitude"));
  sBuf.append(',');
  sBuf.append(latLang.get(3).get("longitude"));
  sBuf.append("+to:");
  sBuf.append(latLang.get(4).get("latitude"));
  sBuf.append(',');
  sBuf.append(latLang.get(4).get("longitude"));

  // sBuf.append("&sensor=true&mode=DRIVING");
  sBuf.append("&key=");
  sBuf.append("Your_API_KEY");

  MISLog.printDebug(sBuf);

  Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
    Uri.parse(sBuf.toString()));
  startActivity(sendLocationToMap);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!