JAVA版高德转GPS坐标

LatLonPoint 实体

package?com;

public?class?LatLonPoint?{

	private?double?latitude;
	private?double?longitude;

	LatLonPoint()?{

	}

	LatLonPoint(double?latitude,?double?longitude)?{
		this.latitude?=?latitude;
		this.longitude?=?longitude;
	}

	public?double?getLatitude()?{
		return?latitude;
	}

	public?void?setLatitude(double?latitude)?{
		this.latitude?=?latitude;
	}

	public?double?getLongitude()?{
		return?longitude;
	}

	public?void?setLongitude(double?longitude)?{
		this.longitude?=?longitude;
	}

	@Override
	public?String?toString()?{
		return?"LatLonPoint?[latitude="?+?latitude?+?",?longitude="?+?longitude?+?"]";
	}
}


转换类

package?com;

public?class?Snippet?{
	private?final?static?double?a?=?6378245.0;?//?长半轴
	private?final?static?double?pi?=?3.14159265358979324;?//?π
	private?final?static?double?ee?=?0.00669342162296594323;?//?e2
	
	public?static?void?main(String[]?args)?{
		double?lat?=?39.993202;
		double?lon?=?116.473207;
		LatLonPoint?gpsPoint?=?toGPSPoint(lat,?lon);
		System.out.println(gpsPoint);
	}
	
	//?GCJ-02?to?WGS-84
	public?static?LatLonPoint?toGPSPoint(double?latitude,?double?longitude)?{
	????????LatLonPoint?dev?=?calDev(latitude,?longitude);
	????????double?retLat?=?latitude?-?dev.getLatitude();
	????????double?retLon?=?longitude?-?dev.getLongitude();
	????????for?(int?i?=?0;?i??137.8347)
	????????????return?true;
	????????if?(lat??55.8271)
	????????????return?true;
	????????return?false;
	}
	
	//?计算纬度
	private?static?double?calLat(double?x,?double?y)?{
	????????double?resultLat?=?-100.0?+?2.0?*?x?+?3.0?*?y?+?0.2?*?y?*?y?+?0.1?*?x?*?y?+?0.2?*?Math.sqrt(Math.abs(x));
	????????resultLat?+=?(20.0?*?Math.sin(6.0?*?x?*?pi)?+?20.0?*?Math.sin(2.0?*?x?*?pi))?*?2.0?/?3.0;
	????????resultLat?+=?(20.0?*?Math.sin(y?*?pi)?+?40.0?*?Math.sin(y?/?3.0?*?pi))?*?2.0?/?3.0;
	????????resultLat?+=?(160.0?*?Math.sin(y?/?12.0?*?pi)?+?320?*?Math.sin(y?*?pi?/?30.0))?*?2.0?/?3.0;
	????????return?resultLat;
	}
	
	//?计算经度
	private?static?double?calLon(double?x,?double?y)?{
	????????double?resultLon?=?300.0?+?x?+?2.0?*?y?+?0.1?*?x?*?x?+?0.1?*?x?*?y?+?0.1?*?Math.sqrt(Math.abs(x));
	????????resultLon?+=?(20.0?*?Math.sin(6.0?*?x?*?pi)?+?20.0?*?Math.sin(2.0?*?x?*?pi))?*?2.0?/?3.0;
	????????resultLon?+=?(20.0?*?Math.sin(x?*?pi)?+?40.0?*?Math.sin(x?/?3.0?*?pi))?*?2.0?/?3.0;
	????????resultLon?+=?(150.0?*?Math.sin(x?/?12.0?*?pi)?+?300.0?*?Math.sin(x?/?30.0?*?pi))?*?2.0?/?3.0;
	????????return?resultLon;
	}
}






同类文章