public AMapLocation fromGpsToAmap(Location location) {
AMapLocation aMapLocation = new AMapLocation(location);
CoordinateConverter converter = new CoordinateConverter(mContext);
converter.from(CoordinateConverter.CoordType.GPS);
try {
converter.coord(new DPoint(location.getLatitude(), location.getLongitude()));
DPoint desLatLng = converter.convert();
aMapLocation.setLatitude(desLatLng.getLatitude());
aMapLocation.setLongitude(desLatLng.getLongitude());
} catch (Exception e) {
e.printStackTrace();
}
return aMapLocation;
}
public AMapLocation fromGpsToAmap(Location location) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
latLng = CoordinateUtil.transformFromWGSToGCJ(latLng);
AMapLocation aMapLocation = new AMapLocation(location);
aMapLocation.setLatitude(latLng.latitude);
aMapLocation.setLongitude(latLng.longitude);
return aMapLocation;
}
public class CoordinateUtil {
private static double a = 6378245.0;
private static double ee = 0.00669342162296594323;
/**
* 手机GPS坐标转火星坐标
*
* @param wgLoc
* @return
*/
public static LatLng transformFromWGSToGCJ(LatLng wgLoc) {
//如果在国外,则默认不进行转换
if (outOfChina(wgLoc.latitude, wgLoc.longitude)) {
return new LatLng(wgLoc.latitude, wgLoc.longitude);
}
double dLat = transformLat(wgLoc.longitude - 105.0,
wgLoc.latitude - 35.0);
double dLon = transformLon(wgLoc.longitude - 105.0,
wgLoc.latitude - 35.0);
double radLat = wgLoc.latitude / 180.0 * Math.PI;
double magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Math.PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * Math.PI);
return new LatLng(wgLoc.latitude + dLat, wgLoc.longitude + dLon);
}
public static double transformLat(double x, double y) {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y
+ 0.2 * Math.sqrt(x > 0 ? x : -x);
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x
* Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0
* Math.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y
* Math.PI / 30.0)) * 2.0 / 3.0;
return ret;
}
public static double transformLon(double x, double y) {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1
* Math.sqrt(x > 0 ? x : -x);
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x
* Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0
* Math.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x
/ 30.0 * Math.PI)) * 2.0 / 3.0;
return ret;
}
public static boolean outOfChina(double lat, double lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有