关于知道区块的geohash值,求区块中点坐标和四角坐标

本文介绍了如何根据区块的geohash值或GPS信息,使用geohash工具类和LocationBean实体类来计算区块的中心点以及四角坐标。提供了一个geohash在线测试工具以辅助理解这一过程。
摘要由CSDN通过智能技术生成

条件:先知道该区块geohash值或者该区块任意一点gps
推荐测试工具:geohash在线
geohash工具类

public class GeoHash {
   
	private LocationBean location;
	/**
	 * 1 2500km;2 630km;3 78km;4 20km
	 * 5 2.4km; 6 610m; 7 76m; 8 19m
	 */
	private int hashLength = 7; //经纬度转化为geohash长度
	private int latLength = 20; //纬度转化为二进制长度
	private int lngLength = 20; //经度转化为二进制长度
	
	private double minLat;//每格纬度的单位大小
	private double minLng;//每个经度的单位大小
	private static final char[] CHARS = {
   '0', '1', '2', '3', '4', '5', '6', '7', 
				'8', '9', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 
				'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
	private static HashMap<Character, Integer> CHARSMAP;
	
	static {
   
		CHARSMAP = new HashMap<Character, Integer>();
		for (int i = 0; i < CHARS.length; i++) {
   
			CHARSMAP.put(CHARS[i], i);
		}
	}
	
	public GeoHash(double lat, double lng) {
   
		location = new LocationBean(lat, lng);
		setMinLatLng();
	}
	public GeoHash() {
   
		super();
	}
	public int gethashLength() {
   
		return hashLength;
	}
	
	/**
	 * 
	 * @Description: 设置经纬度的最小单位
	 */
	private void setMinLatLng() {
   
		minLat = LocationBean.MAXLAT - LocationBean.MINLAT;
		for (int i = 0; i < latLength; i++) {
   
			minLat /= 2.0;
		}
		minLng = LocationBean.MAXLNG - LocationBean.MINLNG;
		for (int i = 0; i < lngLength; i++) {
   
			minLng /= 2.0;
		}
	}
	
	/**
	 * @return
	 * @Description: 求所在坐标点及周围点组成的九个
	 */
	public List<String> getGeoHashBase32For9() {
   
		double leftLat = location.getLat() - minLat;
		double rightLat = location.getLat() + minLat;
		double upLng = location.getLng() - minLng;
		double downLng = location.getLng() + minLng;
		List<String> base32For9 = new ArrayList<String>();
		//左侧从上到下 3个
		String leftUp = getGeoHashBase32(leftLat, upLng);
		if (!(leftUp == null || "".equals(leftUp))) {
   
			base32For9.add(leftUp);
		}
		String leftMid = getGeoHashBase32(leftLat, location.getLng());
		if (!(leftMid == null || "".equals(leftMid))) {
   
			base32For9.add(leftMid);
		}
		String leftDown = getGeoHashBase32(leftLat, downLng);
		if (!(leftDown == null || "".equals(leftDown))) {
   
			base32For9.add(leftDown);
		}
		//中间从上到下 3个
		String midUp = getGeoHashBase32(location.getLat(), upLng);
		if (!(midUp == null || "".equals(midUp))) {
   
			base32For9.add(midUp);
		}
		String midMid = getGeoHashBase32(location.getLat(), location.getLng());
		if (!(midMid == null || "".equals(midMid))) {
   
			base32For9.add(midMid);
		}
		String midDown = getGeoHashBase32(location.getLat(), downLng);
		if (!(midDown == null || "".equals(midDown))) {
   
			base32For9.add(midDown);
		}
		//右侧从上到下 3个
		String rightUp = getGeoHashBase32(rightLat, upLng);
		if (!(rightUp == null || "".equals(rightUp))) {
   
			base32For9.add(rightUp);
		}
		String rightMid = getGeoHashBase32(rightLat, location
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值