Android中中GPS坐标转换为高德地图坐标详解坐标转换为高德地图坐标详解
一、坐标分类一、坐标分类
地图坐标大致分为几种:
1、GPS、WGS84,也就是原始坐标体系,这是国际公认的世界标准坐标体系;
2、GCJ-02,又称为“火星坐标”,国家测绘局在02年发布的坐标体系,在国内,至少得使用此坐标体系,比如:google、
高德、腾讯地图等;
3、其他特殊坐标体系,一般都是由火星坐标通过偏移算法计算得出的,比如百度使用的是BD-09坐标,搜狗使用的是自
己的搜狗坐标。
二、坐标转换二、坐标转换
1、使用高德地图、使用高德地图sdk转换转换
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;
}
但是在我的项目里面,当使用上面方法的高德地图版本的jar包后,编译的时候友盟总是提示我有包冲突,但是经历无数的寻
找,都没找出冲突的地方,当我把友盟统计的包引用去掉,编译正常与行了。这里我被友盟坑了,但是必须要保留友盟统计。
我只能放弃新的定位包,使用老版本的,也就不能用上面这个方式了。
2、自己转换、自己转换
通过在网上的搜索,找到一篇文章http://www.eoeandroid.com/forum.php?mod=viewthread&tid=332419,能很好的解决我的
问题,也就是我们自己转换坐标,方法如下。
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;
}
CoordinateUtil.java
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,
评论0