欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

记要一些常用的函数

更新时间: 2014-01-05 02:33:48 责任编辑: Author_N1

 

记录一些常用的函数
public static String convertInputStreamToString(InputStream is) {

	StringBuilder result = new StringBuilder();

	if (is != null)
		try {
			InputStreamReader inputReader = new InputStreamReader(is);
			BufferedReader bufReader = new BufferedReader(inputReader);
			String line = "";
			while ((line = bufReader.readLine()) != null)
				result.append(line);

			bufReader.close();
			inputReader.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	return result.toString();
}

public static boolean isEmpty(String string) {
    return string == null || string.length() == 0;
}

public static boolean isNumeric(String strNumeric) {
	if (isEmpty(strNumeric))
		return false;

	String patternStr = "^[-+]?\\d+(\\.\\d+)?$";

	if (Pattern.matches(patternStr, strNumeric))
		return true;
	else
		return false;
}

public static float getDistance(double lat1, double lon1, double lat2, double lon2) {

    int EARTH_RADIUS_KM = 6371;

	// if there's unavailable location (0,0), return 0
	if (lat1 == 0 || lon1 == 0 || lat2 == 0 || lon2 == 0)
		return 0;

	double lat1Rad = Math.toRadians(lat1);
	double lat2Rad = Math.toRadians(lat2);
	double deltaLonRad = Math.toRadians(lon2 - lon1);

	double km = Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad) + Math.cos(lat1Rad)
			* Math.cos(lat2Rad) * Math.cos(deltaLonRad))
			* EARTH_RADIUS_KM;

	return km;
}
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:33:48
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/11457/
本文WWW.DOC100.NET DOC100.NET版权所有。