package cn.huge.module.utils;
|
|
import cn.huge.base.common.utils.HttpClientUtils;
|
import com.alibaba.fastjson.JSONObject;
|
import com.google.common.collect.Maps;
|
|
import java.util.Map;
|
|
/**
|
* @title: 百度地图工具类
|
* @description: 百度地图工具类
|
* @company: hugeinfo
|
* @author: liyj
|
* @time: 2021-11-05 16:51:48
|
* @version: 1.0.0
|
*/
|
public class BaiduMapUtils {
|
|
public static void main(String[] args) {
|
|
}
|
|
/**
|
* 百度APi参数
|
*/
|
private static final String ak = "roXW0LCjo6P9EnCZgG3O1cBlMzvyapwY";
|
private static final String output = "json";
|
private static final String callback = "showLocation";
|
private static final String geocodingUrl = "http://api.map.baidu.com/geocoding/v3/";
|
private static final String reverseUrl = "http://api.map.baidu.com/reverse_geocoding/v3/";
|
|
/**
|
* 根据详细地址获取坐标值
|
* @param address 详细地址
|
* @param city 城市
|
* @return JSONObject
|
*/
|
public static JSONObject getCoordinateByAddr(String address, String city) {
|
Map<String, String> parameters = Maps.newHashMap();
|
parameters.put("ak", ak);
|
parameters.put("address", address);
|
parameters.put("city", city);
|
parameters.put("output", output);
|
String json = HttpClientUtils.httpGet(geocodingUrl, parameters, null);
|
|
JSONObject data = JSONObject.parseObject(json);
|
JSONObject data1=JSONObject.parseObject(data.getString("result"));
|
JSONObject data2=JSONObject.parseObject(data1.getString("location"));
|
System.out.println(data2.toString());
|
return data2;
|
}
|
|
/**
|
* 根据坐标获取详细地址
|
* @param lat 经度
|
* @param lng 维度
|
* @param coordtype 坐标类型,目前支持的坐标类型包括:bd09ll(百度经纬度坐标)、bd09mc(百度米制坐标)、gcj02ll(国测局经纬度坐标,仅限中国)、wgs84ll( GPS经纬度)
|
* @return String
|
*/
|
public static String getAddressByCoordinate(String lat, String lng, String coordtype) {
|
Map<String, String> parameters = Maps.newHashMap();
|
parameters.put("location", lat + "," + lng);
|
parameters.put("coordtype", coordtype);
|
parameters.put("ak", ak);
|
parameters.put("output", output);
|
String json = HttpClientUtils.httpGet(reverseUrl, parameters, null);
|
|
JSONObject data = JSONObject.parseObject(json);
|
JSONObject data1=JSONObject.parseObject(data.getString("result"));
|
JSONObject data2=JSONObject.parseObject(data1.getString("addressComponent"));
|
String district =data2.getString("district");
|
System.out.println(district);
|
return district;
|
}
|
|
}
|
/**
|
* -------------------_ooOoo_-------------------
|
* ------------------o8888888o------------------
|
* ------------------88" . "88------------------
|
* ------------------(| -_- |)------------------
|
* ------------------O\ = /O------------------
|
* ---------------____/`---'\____---------------
|
* -------------.' \\| |// `.-------------
|
* ------------/ \\||| : |||// \------------
|
* -----------/ _||||| -:- |||||- \-----------
|
* -----------| | \\\ - /// | |-----------
|
* -----------| \_| ''\---/'' | |-----------
|
* -----------\ .-\__ `-` ___/-. /-----------
|
* ---------___`. .' /--.--\ `. . __----------
|
* ------."" '< `.___\_<|>_/___.' >'"".-------
|
* -----| | : `- \`.;`\ _ /`;.`/ - ` : | |-----
|
* -----\ \ `-. \_ __\ /__ _/ .-` / /-----
|
* ======`-.____`-.___\_____/___.-`____.-'======
|
* -------------------`=---='
|
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
* ---------佛祖保佑---hugeinfo---永无BUG----------
|
*/
|