1 android studio 打印log如下:
com.amap.api.maps.AMapException: 非法坐标值
01-03 10:48:09.878 16395-16477/? I/SensorState: sensor:2 enable:false uid:10398
01-03 10:48:09.878 16395-16477/? I/SensorState: removeSensor,mHandles:{}
01-03 10:48:09.878 12597-12597/cn.xa.tjy W/System.err: at com.amap.api.maps.model.LatLng.<init>(LatLng.java:58)
01-03 10:48:09.878 16395-16477/? I/PGServer: report state:4 event type:2 pid:2 uid:10398 pkg:null to pid: 15595
01-03 10:48:09.878 12597-12597/cn.xa.tjy W/System.err: at com.amap.api.maps.model.LatLng.<init>(LatLng.java:35)
原因分析:
先看下高德地图原码
public LatLng(double var1, double var3, boolean var5) {
if(var5) {
if(-180.0D <= var3 && var3 < 180.0D) {
this.longitude = var3;
} else {
this.longitude = ((var3 - 180.0D) % 360.0D + 360.0D) % 360.0D - 180.0D;
}
if(var1 < -90.0D || var1 > 90.0D) {
try {
throw new AMapException("非法坐标值");
} catch (AMapException var7) {
var7.printStackTrace();
}
}
this.latitude = Math.max(-90.0D, Math.min(90.0D, var1));
} else {
this.latitude = var1;
this.longitude = var3;
}
}
参数介绍:创建var1 :纬度,var2:经度,var5:是否检查坐标
- latlng创建的时候new LatLng(double v1,duble v2)会对坐标进行检查
- 纬度检查规则如下:
if(var1 < -90.0D || var1 > 90.0D) {
try {
throw new AMapException("非法坐标值");
} catch (AMapException var7) {
var7.printStackTrace();
}
}
this.latitude = Math.max(-90.0D, Math.min(90.0D, var1));
this.longitude = var3;
} else {
this.longitude = ((var3 - 180.0D) % 360.0D + 360.0D) % 360.0D - 180.0D;
}
常见原因:new Latlng(lat,lng),lat,lng数据搞错了,创建latlng的时候换个位置就可以了。^_^