(2).路线规划-步行模式
package com.jsxs.TentcentMap.routePlanning; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/5 20:44 * @PackageName:com.jsxs.TentcentMap.routePlanning * @ClassName: Walking * @Description: TODO 步行 * @Version 1.0 */ public class Walking { public static JSONArray getWalking(String startLan,String startLon,String endLan,String endLon,String key){ String keyURL="https://apis.map.qq.com/ws/direction/v1/walking/?from="+startLan+","+startLon+"&to="+endLan+","+endLon+"&key="+key; System.out.println(keyURL); String s = TencentMapUtils.getTencentMap(keyURL).toString(); // 2. JSON字符串转换为JSON对象 JSONObject jsonObject = JSONObject.parseObject(s); JSONObject result = (JSONObject)jsonObject.get("result"); JSONArray routes = (JSONArray)result.get("routes"); return routes; } public static void main(String[] args) { JSONArray array = getWalking("39.915285", "116.403857", "39.915285", "116.803857", "你的密钥"); System.out.println("总距离是:"+array.getJSONObject(0).get("distance")+"米"); System.out.println("预计消耗时间是:"+array.getJSONObject(0).get("duration")+"分钟"); // 详细方案的数组 JSONArray steps = (JSONArray)array.getJSONObject(0).get("steps"); for (int i = 0; i < steps.size(); i++) { System.out.println(steps.getJSONObject(i).get("instruction")+" -》 注意是:"+steps.getJSONObject(i).get("act_desc")); } } }
(3).路线规划-骑行模式
package com.jsxs.TentcentMap.routePlanning; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/5 20:57 * @PackageName:com.jsxs.TentcentMap.routePlanning * @ClassName: bicycling * @Description: TODO * @Version 1.0 */ public class bicycling { public static JSONArray getBicycling(String startLan,String startLon,String endLan,String endLon,String key){ String keyURL="https://apis.map.qq.com/ws/direction/v1/bicycling/?from="+startLan+","+startLon+"&to="+endLan+","+endLon+"&key="+key; System.out.println(keyURL); String s = TencentMapUtils.getTencentMap(keyURL).toString(); // 2. JSON字符串转换为JSON对象 JSONObject jsonObject = JSONObject.parseObject(s); JSONObject result = (JSONObject)jsonObject.get("result"); JSONArray routes = (JSONArray)result.get("routes"); return routes; } public static void main(String[] args) { JSONArray array = getBicycling("39.915285", "116.403857", "39.915285", "116.803857", "你的密钥"); System.out.println("总距离是:"+array.getJSONObject(0).get("distance")+"米"); System.out.println("预计消耗时间是:"+array.getJSONObject(0).get("duration")+"分钟"); // 详细方案的数组 JSONArray steps = (JSONArray)array.getJSONObject(0).get("steps"); for (int i = 0; i < steps.size(); i++) { System.out.println(steps.getJSONObject(i).get("instruction")+" -》 注意是:"+steps.getJSONObject(i).get("act_desc")); } } }
(4).路线规划-公交模式
差异化 很严重...
package com.jsxs.TentcentMap.routePlanning; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/5 21:02 * @PackageName:com.jsxs.TentcentMap.routePlanning * @ClassName: transit * @Description: TODO * @Version 1.0 */ public class transit { public static JSONArray getTransit(String startLan,String startLon,String endLan,String endLon,String key){ String keyURL="https://apis.map.qq.com/ws/direction/v1/transit/?from="+startLan+","+startLon+"&to="+endLan+","+endLon+"&key="+key; System.out.println(keyURL); String s = TencentMapUtils.getTencentMap(keyURL).toString(); // 2. JSON字符串转换为JSON对象 JSONObject jsonObject = JSONObject.parseObject(s); JSONObject result = (JSONObject)jsonObject.get("result"); JSONArray routes = (JSONArray)result.get("routes"); return routes; } public static void main(String[] args) { JSONArray array = getTransit("39.915285", "116.403857", "39.915285", "116.803857", "xxxxxxx"); System.out.println("总距离是:"+array.getJSONObject(0).get("distance")+"米"); System.out.println("预计消耗时间是:"+array.getJSONObject(0).get("duration")+"分钟"); // 详细方案的数组 JSONArray steps = (JSONArray)array.getJSONObject(0).get("steps"); // 1.步行 JSONArray steps1 = (JSONArray)steps.getJSONObject(0).get("steps"); System.out.println("*************导航开始*************"); for (int i = 0; i < steps1.size(); i++) { System.out.println(steps1.getJSONObject(i).get("instruction")+" -》 注意是:"+steps1.getJSONObject(i).get("act_desc")); if (i==steps1.size()-1){ System.out.println(steps1.getJSONObject(i).get("instruction")); System.out.println("*************步行已截至*************"); } } // 2.地铁 JSONArray lines = (JSONArray)steps.getJSONObject(1).get("lines"); for (int i = 0; i < lines.size(); i++) { JSONArray stations = (JSONArray)lines.getJSONObject(i).get("stations"); System.out.println("乘坐"+lines.getJSONObject(i).get("title")+" 经过站点个数为:"+lines.getJSONObject(i).get("station_count")+" 预计消费"+lines.getJSONObject(i).get("price")+"分人民币"); System.out.println("站点分别是: "); for (int i1 = 0; i1 < stations.size(); i1++) { System.out.print(stations.getJSONObject(i1).get("title")+"->"); if (i1==stations.size()-1){ System.out.println(stations.getJSONObject(i1).get("title")); System.out.println("*************地铁已截至*************"); } } } // 3. ....后续...暂且不更新 } }
(5).路线规划-货车模式
每日只能调用一次数据
package com.jsxs.TentcentMap.routePlanning; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/6 20:17 * @PackageName:com.jsxs.TentcentMap.routePlanning * @ClassName: Truck * @Description: TODO 货车: 一日只能调用一次... * @Version 1.0 */ public class Truck { public static JSONArray getTruck(String startLn,String startLo,String endLn,String endLo,String key){ String keyURL="https://apis.map.qq.com/ws/direction/v1/trucking?from="+startLn+","+startLo+"&to="+endLn+","+endLo+"&key="+key; System.out.println(keyURL); String s = TencentMapUtils.getTencentMap(keyURL).toString(); JSONObject jsonObject = JSONObject.parseObject(s); JSONObject result = (JSONObject)jsonObject.get("result"); JSONArray routes = (JSONArray)result.get("routes"); return routes; } public static void main(String[] args) { JSONArray array = getTruck("40.023408", "116.318436", "39.767381", "116.337662", "xxxxxx"); System.out.println("总距离:"+array.getJSONObject(0).get("distance")+"米 预计消耗时间"+array.getJSONObject(0).get("duration")+"分钟"); for (int i = 0; i < array.size(); i++) { JSONArray steps = (JSONArray)array.getJSONObject(i).get("steps"); for (int i1 = 0; i1 < steps.size(); i1++) { System.out.println(i1+" "+steps.getJSONObject(i1).get("instruction")); } } } }
11.行政区划
(1).获取全部行政区划
package com.jsxs.TentcentMap.AdministrativeDivision; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/6 20:48 * @PackageName:com.jsxs.TentcentMap.AdministrativeDivision * @ClassName: provincialAndUrbanAreas * @Description: TODO 全国省市区 * @Version 1.0 */ public class provincialAndUrbanAreas { public static JSONArray getProvincialAndUrbanAreas(String key) { String urlKey="https://apis.map.qq.com/ws/district/v1/list?key="+key; System.out.println(urlKey); String s = TencentMapUtils.getTencentMap(urlKey).toString(); JSONObject jsonObject = JSONObject.parseObject(s); JSONArray result = (JSONArray)jsonObject.get("result"); // System.out.println(result); return result; } public static void main(String[] args) { JSONArray array = getProvincialAndUrbanAreas("xxx"); // 数组里面存放着数组。然后第二个数组存放着对象 JSONArray jsonArray = array.getJSONArray(0); for (int i = 0; i < jsonArray.size(); i++) { System.out.println("邮政编号:"+jsonArray.getJSONObject(i).get("id")+"->"+jsonArray.getJSONObject(i).get("fullname")); } } }
(2).获取子级行政区划
package com.jsxs.TentcentMap.AdministrativeDivision; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsxs.TencentMapUtils.TencentMapUtils; /** * @Author Jsxs * @Date 2023/4/6 21:12 * @PackageName:com.jsxs.TentcentMap.AdministrativeDivision * @ClassName: subAdministrativeDivision * @Description: TODO 子级行政区划 * @Version 1.0 */ public class subAdministrativeDivision { public static JSONArray getSubAdministrativeDivision(String id,String key){ String keyURL="https://apis.map.qq.com/ws/district/v1/getchildren?id="+id+"&key="+key; System.out.println(keyURL); String s = TencentMapUtils.getTencentMap(keyURL).toString(); JSONObject jsonObject = JSONObject.parseObject(s); JSONArray result = (JSONArray)jsonObject.get("result"); return result; } public static void main(String[] args) { JSONArray array = getSubAdministrativeDivision("410000", "xxxx"); JSONArray jsonArray = array.getJSONArray(0); for (int i = 0; i < jsonArray.size(); i++) { System.out.println("邮政编号:"+jsonArray.getJSONObject(i).get("id")+"->"+jsonArray.getJSONObject(i).get("fullname")); } } }