//WGS-84 to GCJ-02 private void Wgs84ToGcj02() { if (Wgs84 == null || this.outOfChina(Wgs84)) { Gcj02 = Wgs84; } var t = this.delta(Wgs84); Gcj02.lng = t.lng + Wgs84.lng; Gcj02.lat = t.lat + Wgs84.lat; }
//GCJ-02 to WGS-84 private void Gcj02ToWgs84() { if (Gcj02 == null || this.outOfChina(Gcj02)) { Wgs84 = Gcj02; } var t = this.delta(Gcj02); Wgs84.lng = Gcj02.lng - t.lng; Wgs84.lat = Gcj02.lat - t.lat; }
private bool outOfChina(Gps _t) { if (_t.lng < 72.004 || _t.lng > 137.8347) { return(true); } if (_t.lat < 0.8293 || _t.lat > 55.8271) { return(true); } return(false); }
private Gps delta(Gps t) { var a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。 var ee = 0.00669342162296594323; // ee: 椭球的偏心率。 var dLat = this.transformLat(t.lng - 105.0, t.lat - 35.0); var dLng = this.transformLng(t.lng - 105.0, t.lat - 35.0); var radLat = t.lat / 180.0 * PI; var magic = Math.Sin(radLat); magic = 1 - ee * magic * magic; var sqrtMagic = Math.Sqrt(magic); return(new Gps() { lat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI), lng = (dLng * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * PI) }); }
public GpsHelper(Gps _v, GpsType type) { if (type == GpsType.Wgs84) { Wgs84 = _v; Wgs84ToDfm(); Wgs84ToGcj02(); Gcj02ToBd09(); } else if (type == GpsType.Gcj02) { Gcj02 = _v; Gcj02ToWgs84(); Wgs84ToDfm(); Gcj02ToBd09(); } else if (type == GpsType.Bd09) { Bd09 = _v; Bd09ToGcj02(); Gcj02ToWgs84(); Wgs84ToDfm(); } }