zoukankan      html  css  js  c++  java
  • 百度地图API调用转换WGS坐标以及上传点到鹰视

    * 根据某个对象的经纬度和高度在百度地图上绘制出车辆的轨迹
    * 首先根据离散的点,拟合出一个平滑的曲线
    * 然后将采样后的曲线绘制在百度地图上
    * 首先获取百度的AK : 121
    * service:
    * 开发者使用一个百度的service可以管理很多的电动车,每一个电动车称为一个entity,service的service_id是唯一的,开发者可以使用轨迹管理平台管理service,包括创建,编辑和查看
    * entity:
    * 一个设备有一个唯一的entity_name作为唯一标识,一个service最多同时管理一百万个entity,鹰眼web api提供entity的增删改查的接口
    * entity column:
    * entity自定义的字段,可以用于描述eneity
    * track:
    * entity移动产生的轨迹,由point组成,数量可以没有限制,web api提供了添加,批量添加,查询历史轨迹的接口。
    * track column:
    * 除了,坐标,速度,方向,定位时间等轨迹的系统字段之外,可以添加自定义的字段。例如心率,油量等等,可以自定义10个字段
    * fence:
    * 地理围栏,是一个区域,离开这个区域报警
    * object:
    * 代表图像和视频对象,支持上传图像数据,支持图像数据的存储,查询和下载
     
      1 import java.io.BufferedReader;
      2 import java.io.BufferedWriter;
      3 import java.io.IOException;
      4 import java.io.InputStreamReader;
      5 import java.io.OutputStreamWriter;
      6 import java.io.PrintWriter;
      7 import java.net.MalformedURLException;
      8 import java.net.URL;
      9 import java.net.URLConnection;
     10 import java.util.ArrayList;
     11 import java.util.List;
     12 import java.util.Map;
     13 
     14 import org.json.JSONArray;
     15 import org.json.JSONObject;
     16 
     17 
     18 
     19 
     20 /**
     21  * 
     22  * @author Administrator
     23  *
     24  */
     25 public class BaiDuMapApi {
     26 
     27     public static final String ak="121";
     28     public static final String coord_type_input_bd="bd09ll";
     29     public static final String coord_type_input_wgs="wgs84";
     30     /**
     31      * WGS坐标转化为baidu需要的坐标,返回的字符串等待处理。。。这是一个GET请求
     32      */
     33     public static String WGS2BD09(double lon,double lat) throws IOException {
     34         String TargetGetURL="http://api.map.baidu.com/geoconv/v1/?coords="+lon+",+"+lat+"&from=1&to=5&ak=9xLNrzeQwWYI3uidYtcLIDlWeLXo7vud";//GET请求
     35         String result="";
     36         OutputStreamWriter outputStreamWriter=null;
     37         BufferedReader bufferedReader=null;
     38         URL url=new URL(TargetGetURL);
     39         URLConnection connection=url.openConnection();
     40         connection.setRequestProperty("accept", "*/*");
     41         connection.connect();
     42         //遍历响应头字段
     43         Map<String, List<String>> map=connection.getHeaderFields();
     44         for(String key:map.keySet()) {
     45             //System.out.println(key+"->"+map.get(key));
     46         }
     47         bufferedReader=new BufferedReader(new InputStreamReader(connection.getInputStream()));
     48         String line;
     49         while((line=bufferedReader.readLine())!=null)
     50             result+=line;
     51         //System.out.println(result);
     52         return result;
     53     }
     54     /**
     55      * 返回的字符串处理一下,返回一个坐标对象
     56      * @param result
     57      * @return
     58      */
     59     public static Lon_Lat_Class FilterLocationFromResult(String result) {
     60         //System.out.println(result);
     61         JSONObject my_json =new JSONObject(result);
     62         //List<Double> location=new ArrayList<>();
     63         Lon_Lat_Class lon_Lat_Class = new Lon_Lat_Class();
     64         //System.out.println(my_json.getString("status"));
     65         if(my_json.getInt("status")==0) {
     66             
     67             //System.out.println("转换坐标成功");
     68             JSONArray jsonArray=my_json.getJSONArray("result");
     69             for (int i = 0; i < jsonArray.length(); i++) {
     70                 JSONObject jsonObject=jsonArray.getJSONObject(i);
     71                 Double loc1=jsonObject.getDouble("x");
     72                 Double loc2=jsonObject.getDouble("y");
     73                 lon_Lat_Class.setLongitude(loc1);
     74                 lon_Lat_Class.setLatitude(loc2);
     75             }
     76             //System.out.println(my_json.getJSONArray("result"));
     77             return lon_Lat_Class;
     78         }
     79         System.out.println("坐标转换失败");
     80         return lon_Lat_Class;
     81     }
     82     
     83     //还要实现一个POST请求用于将指定坐标点上传拟合成一个曲线
     84     
     85     public static String SendPost(String URL,String Param) throws IOException {
     86         PrintWriter out=null;
     87         BufferedReader in=null;
     88         String result="";
     89         URL realURL=new URL(URL);
     90         URLConnection connection=realURL.openConnection();
     91         connection.setRequestProperty("accept", "*/*");
     92         connection.setRequestProperty("connection", "Keep-Alive");
     93         connection.setDoOutput(true);
     94         connection.setDoInput(true);
     95         out=new PrintWriter(connection.getOutputStream());
     96         //发送请求参数
     97         out.print(Param);
     98         out.flush();
     99         in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
    100         String line;
    101         while((line=in.readLine())!=null)
    102             result+=line;
    103         return result;
    104                 
    105     }
    106     public static void testSendPost(String ak,int service_id,String devId,double lat,double lon,long loc_time,String coord_type_input,double speed,int direction,double height) throws IOException {
    107         String URL="http://yingyan.baidu.com/api/v3/track/addpoint";
    108         String Param="ak"+"="+ak+"&"+
    109                     "service_id"+"="+service_id+"&"+
    110                     "entity_name"+"="+devId+"&"+
    111                     "latitude"+"="+lat+"&"+
    112                     "longitude"+"="+lon+"&"+
    113                     "loc_time"+"="+loc_time+"&"+
    114                     "coord_type_input"+"="+coord_type_input+"&"+
    115                     "speed"+"="+speed+"&"+
    116                     "direction"+"="+direction+"&"+
    117                     "height"+"="+height;
    118         System.out.println(Param);
    119         String result=SendPost(URL, Param);
    120         System.out.println(result);
    121         JSONObject my_json=new JSONObject(result);
    122         System.out.println(my_json.getInt("status"));
    123     }
    124     
    125     public static void main(String[] args) throws IOException {
    126 
    127 //        String result=WGS2BD09(LambdaTest01.InterSectionLng, LambdaTest01.InterSectionLat);
    128 //        System.out.println(result);
    129 //        System.out.println(FilterLocationFromResult(result));
    130 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983425, latitude=30.18893166666667, longitude=120.19190166666667, satellite=15, hdop=0.84, altitude=11.8, speed=13.15, direction=9.15]
    131 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983427, latitude=30.188995, longitude=120.19190666666667, satellite=15, hdop=0.84, altitude=12.4, speed=11.87, direction=354.48]
    132 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983430, latitude=30.189076666666665, longitude=120.19189499999999, satellite=15, hdop=0.84, altitude=12.9, speed=11.59, direction=346.11]
    133 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983432, latitude=30.189136666666666, longitude=120.19188666666666, satellite=15, hdop=0.84, altitude=11.5, speed=12.89, direction=352.29]
    134 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983435, latitude=30.189213333333335, longitude=120.19188666666666, satellite=15, hdop=0.84, altitude=10.5, speed=11.11, direction=343.92]
    135 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983437, latitude=30.189258333333335, longitude=120.19187333333333, satellite=15, hdop=0.84, altitude=12.9, speed=12.13, direction=345.98]
    136 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983440, latitude=30.189345000000003, longitude=120.19184666666666, satellite=15, hdop=0.84, altitude=13.1, speed=10.91, direction=353.62]
    137 //        ObjectProperty [devId=DD7FDC41, timestamp=1538983444, latitude=30.189450000000004, longitude=120.19183, satellite=16, hdop=0.7, altitude=12.2, speed=11.09, direction=358.76]
    138 //      ObjectProperty [devId=DD7FDC41, timestamp=1538983447, latitude=30.189543333333337, longitude=120.19183, satellite=15, hdop=0.84, altitude=12.1, speed=12.19, direction=3.75]
    139         //testSendPost(ak, 205899, "DD7FDC41", 30.18893166666667, 120.19190166666667, 1538983425, coord_type_input_wgs, 0.98, 319, 12.2);
    140 //        testSendPost(ak, 205899, "DD7FDC41", 30.188995000000000, 120.19190666666667, 1538983427, coord_type_input_wgs, 0.98, 319, 12.2);
    141 //        testSendPost(ak, 205899, "DD7FDC41", 30.189076666666665, 120.19189499999999, 1538983430, coord_type_input_wgs, 0.98, 319, 12.2);
    142 //        testSendPost(ak, 205899, "DD7FDC41", 30.189136666666666, 120.19188666666666, 1538983432, coord_type_input_wgs, 0.98, 319, 12.2);
    143 //        testSendPost(ak, 205899, "DD7FDC41", 30.189213333333335, 120.19188666666666, 1538983435, coord_type_input_wgs, 0.98, 319, 12.2);
    144 //        testSendPost(ak, 205899, "DD7FDC41", 30.189258333333335, 120.19187333333333, 1538983437, coord_type_input_wgs, 0.98, 319, 12.2);
    145 //        testSendPost(ak, 205899, "DD7FDC41", 30.189345000000003, 120.19184666666666, 1538983440, coord_type_input_wgs, 0.98, 319, 12.2);
    146 //        testSendPost(ak, 205899, "DD7FDC41", 30.189450000000004, 120.19183, 1538983444, coord_type_input_wgs, 0.98, 319, 12.2);
    147 //        testSendPost(ak, 205899, "DD7FDC41", 30.189543333333337, 120.19183, 1538983447, coord_type_input_wgs, 0.98, 319, 12.2);
    148 //        //坐标转换
    149         Lon_Lat_Class lon_Lat_Class=BaiDuMapApi.FilterLocationFromResult(BaiDuMapApi.WGS2BD09(120.191689, 30.189142));
    150         //System.out.println(lon_Lat_Class);
    151     }
    152 
    153 }

    万事走心 精益求美


  • 相关阅读:
    Python
    Python
    Redis
    android和.net webservice中的DES加密算法
    android studio中使用recyclerview小白篇(四)
    android studio中使用recyclerview小白篇(三)
    android studio中使用recyclerview小白篇(二)
    android studio中使用recyclerview小白篇(一)
    Fragment之间通过add切换时的显示与隐藏
    android报错:org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject
  • 原文地址:https://www.cnblogs.com/kongchung/p/9914809.html
Copyright © 2011-2022 走看看