java基站定位接口实例

java基站定位接口实例该接口基于LBS数据仓库接口地址:http://api.cellocation.com:81/cell/支持格式:CSV/JSON/XML请求方式:GET请求示例:http://api.cellocation.com:81/cell/?mcc=460&mnc=1&lac=4301&ci=20986&output=xml名称 类型 必填 说明 mcc int 是 mcc国家代码:中国代码460 mnc i

大家好,欢迎来到IT知识分享网。

该接口基于LBS数据仓库

接口地址:http://api.cellocation.com:81/cell/

支持格式: CSV/JSON/XML
请求方式: GET

请求示例:http://api.cellocation.com:81/cell/?mcc=460&mnc=1&lac=4301&ci=20986&output=xml

名称 类型 必填 说明
mcc int mcc国家代码:中国代码 460
mnc int mnc网络类型:0移动,1联通(电信对应sid),十进制
lac int lac(电信对应nid),十进制
ci int cellid(电信对应bid),十进制
coord string 坐标类型(wgs84/gcj02/bd09),默认wgs84
output string 返回格式(csv/json/xml),默认csv

返回数据格式:CSV
errcode,纬度,经度,精度半径,地址

errcode
0: 成功
10000: 参数错误
10001: 无查询结果

示例:
0,39.999024,116.476159,222,”北京市朝阳区望京街道北京市望京实验学校(宝星分校);阜安路与宏泰东街路口西231米”

 

java实例:

public class LocationUtils {
	private static final Logger _log = Logger.getLogger(LocationUtils.class);
	
	private static LocationDao locationDao;
	
	private static String ENCODING = "UTF-8";
    private static int CONNECT_TIMEOUT = 30000;
   // private static int READ_TIMEOUT = 10000;
    private static int READ_TIMEOUT = 30000;
	/**
	 * 获取具体的位置
	 * @param mnc
	 * @param mcc
	 * @param lac
	 * @param ci
	 * @return
	 */
	public static Location getLocation(int mnc, int mcc, int lac, int ci) {
		Location location = new Location();
		
		HttpURLConnection conn = null;
		BufferedReader br = null;
		try {
			StringBuffer sb = new StringBuffer();
			sb.append("http://api.cellocation.com:81/cell?output=json");
			sb.append("&mnc=").append(mnc);
			sb.append("&mcc=").append(mcc);
			sb.append("&lac=").append(lac);
			sb.append("&ci=").append(ci);
			URL url = new URL(sb.toString());
			conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod(ReqMethod.GET);
			conn.setRequestProperty("Accept-Charset", ENCODING);
			conn.setRequestProperty("contentType", "application/json; charset=" + ENCODING);
			conn.setConnectTimeout(CONNECT_TIMEOUT);
			conn.setReadTimeout(READ_TIMEOUT);
			_log.info("line--------"+sb.toString());
//			int responseCode = conn.getResponseCode();
//			_log.debug("responseCode-> " + responseCode);
			
			br = new BufferedReader(new InputStreamReader(conn.getInputStream(), ENCODING));
			String line = null;
			StringBuffer buffer = new StringBuffer();
			while ((line = br.readLine()) != null) {
				buffer.append(line);
			}
			line = buffer.toString();

			JSONObject obj = JSONObject.fromObject(line);
			if(obj.getInt("errcode") == 0){
				location.setSuccess(true);
				location = (Location) JSONObject.toBean(obj, Location.class);
				_log.info("--1:"+obj.getString("address"));
				
			}else{
				location.setSuccess(true);
				location.setErrcode(obj.getInt("errcode")+"");
			}
			
		} catch (Exception e) {
			_log.error(e.getMessage());
			e.printStackTrace();
		}finally{
			if(br != null){
				try{
					br.close();
				}catch(IOException e){
					_log.error("close stream error -> " + e);
				}
			}
			if (conn != null) {
				conn.disconnect();
			}
		}
		
		return location;
	}

	public static double distance(double lon1, double lat1, double lon2, double lat2) {
		double a, b, R;
		R = 6378137; // 地球半径
		lat1 = lat1 * Math.PI / 180.0;
		lat2 = lat2 * Math.PI / 180.0;
		a = lat1 - lat2;
		b = (lon1 - lon2) * Math.PI / 180.0;
		double d;
		double sa2, sb2;
		sa2 = Math.sin(a / 2.0);
		sb2 = Math.sin(b / 2.0);
		d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
		return d;
	}

	public static String getENCODING() {
		return ENCODING;
	}

	public static void setENCODING(String eNCODING) {
		ENCODING = eNCODING;
	}

	public static int getCONNECT_TIMEOUT() {
		return CONNECT_TIMEOUT;
	}

	public static void setCONNECT_TIMEOUT(int cONNECT_TIMEOUT) {
		CONNECT_TIMEOUT = cONNECT_TIMEOUT;
	}

	public static int getREAD_TIMEOUT() {
		return READ_TIMEOUT;
	}

	public static void setREAD_TIMEOUT(int rEAD_TIMEOUT) {
		READ_TIMEOUT = rEAD_TIMEOUT;
	}

	public LocationDao getLocationDao() {
		return locationDao;
	}

	public void setLocationDao(LocationDao locationDao) {
		this.locationDao = locationDao;
	}
	
	
}

 

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/23600.html

(0)
上一篇 2023-09-09 10:00
下一篇 2023-09-09 12:45

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信