• 大小: 5.16MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: Java
  • 标签: 百度地图  

资源简介

参考了百度开发api文档整合,输入出发地和目的地分别定位,并查找两地之间的行车距离、时间以及路径分步骤。

资源截图

代码片段和文件信息

package com.zouyang;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONobject;

public class JsonGet extends HttpServlet{

private static final long serialVersionUID = 1L;

public JsonGet() {
super();
}

public void destroy() {
super.destroy(); // Just puts “destroy“ string in log
// Put your code here
}

public void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
this.doPost(request response);
}

public void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
//System.out.println(“获取JsonGet“);
        JSONobject jsonobject = new JSONobject();
        JSONArray jsonArray = new JSONArray();
        String address = request.getParameter(“address“);
        address = new String(address.getBytes(“iso8859-1“)“utf-8“);
        String key = request.getParameter(“key“);
String geturl = “http://api.map.baidu.com/geocoder?address=“+address+“&output=json&key=“+key;
URL url = new URL(geturl);
    StringBuffer buffer = new StringBuffer();
 // http协议传输
        HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();
        httpUrlConn.setDoOutput(true);
        httpUrlConn.setDoInput(true);
        httpUrlConn.setUseCaches(false);
        httpUrlConn.connect();
        // 将返回的输入流转换成字符串
        InputStream inputStream = httpUrlConn.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream “utf-8“);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String str = null;
        while ((str = bufferedReader.readLine()) != null) {
            buffer.append(str);
        }
        bufferedReader.close();
        inputStreamReader.close();
        // 释放资源
        inputStream.close();
        inputStream = null;
        httpUrlConn.disconnect();
    System.out.println(buffer.toString());
        String json = buffer.toString();
        JSONobject getobject = JSONobject.fromobject(json);
        System.out.println(getobject.get(“status“));
        String result = getobject.get(“result“).toString();
        JSONobject resultobject = JSONobject.fromobject(result);
        System.out.println(resultobject.get(“precise“)+“--“+resultobject.get(“confidence“)+“--“+resultobject.get(“level“));
        String location = resultobject.get(“location“).toString();
        JSONobject locationobject = JSONobject

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-16 14:57  BaiduMap\
     文件        1074  2017-10-18 10:59  BaiduMap\.classpath
     文件        1041  2017-10-16 14:01  BaiduMap\.project
     目录           0  2017-10-16 14:01  BaiduMap\.settings\
     文件         567  2017-10-16 14:01  BaiduMap\.settings\.jsdtscope
     文件         364  2017-10-16 14:01  BaiduMap\.settings\org.eclipse.jdt.core.prefs
     文件         476  2017-10-16 14:01  BaiduMap\.settings\org.eclipse.wst.common.component
     文件         345  2017-10-16 14:01  BaiduMap\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2017-10-16 14:01  BaiduMap\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2017-10-16 14:01  BaiduMap\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2017-10-16 14:57  BaiduMap\WebContent\
     目录           0  2017-10-16 14:01  BaiduMap\WebContent\meta-INF\
     文件          39  2017-10-16 14:01  BaiduMap\WebContent\meta-INF\MANIFEST.MF
     目录           0  2017-10-18 10:34  BaiduMap\WebContent\WEB-INF\
     目录           0  2017-10-18 10:59  BaiduMap\WebContent\WEB-INF\lib\
     文件       93330  2011-04-22 17:44  BaiduMap\WebContent\WEB-INF\lib\json-2.2.1.jar
     文件      159123  2012-06-28 10:17  BaiduMap\WebContent\WEB-INF\lib\json-lib-2.4-jdk15.jar
     文件     5608004  2012-06-28 10:17  BaiduMap\WebContent\WEB-INF\lib\json-parser_fat.jar
     文件         547  2017-10-18 11:06  BaiduMap\WebContent\WEB-INF\web.xml
     文件        7346  2017-10-17 09:01  BaiduMap\WebContent\drive.html
     目录           0  2017-10-16 14:05  BaiduMap\WebContent\js\
     文件       86355  2017-10-16 14:05  BaiduMap\WebContent\js\jquery-3.1.0.min.js
     文件        4043  2017-10-18 13:35  BaiduMap\WebContent\map.html
     目录           0  2017-10-16 14:01  BaiduMap\build\
     目录           0  2017-10-18 10:59  BaiduMap\build\classes\
     目录           0  2017-10-18 10:59  BaiduMap\build\classes\com\
     目录           0  2017-10-18 10:59  BaiduMap\build\classes\com\zouyang\
     文件        4268  2017-10-18 13:33  BaiduMap\build\classes\com\zouyang\JsonGet.class
     目录           0  2017-10-18 10:27  BaiduMap\src\
     目录           0  2017-10-18 10:27  BaiduMap\src\com\
     目录           0  2017-10-18 10:57  BaiduMap\src\com\zouyang\
............此处省略2个文件信息

评论

共有 条评论