This article mainly introduces the latitude and longitude bl and Cartesian coordinates XY of the positive calculation of PHP code, has a certain reference value, now share to everyone, the need for friends can refer to
Here is the Beijing 54 coordinate 6 degree belt. You need to use other coordinates to modify the parameter $_a, $_f.
By Latitude to XY:
<?phpfunction Bltoxy ($latitude, $longitude) {$_a = 6378245.0; $_f = 1.0/298.3; $zoneWide = 6; $PI = 3.14159265353846; $iPI = 0.0174532925199433; 3.1415926535898/180.0; Zonewide = 6; 6-degree bandwidth $ProjNo = floor ($longitude/$zoneWide); $longitude 0 = $ProjNo * $zoneWide + $zoneWide/2; $longitude 0 = $longitude 0 * $iPI; $latitude 0 = 0; $longitude 1 = $longitude * $iPI; The longitude is converted to radians $latitude 1 = $latitude * $iPI; Latitude converted to radians $e 2 = 2 * $_f-$_f * $_F; $ee = $e 2 * (1.0-$e 2); $NN = $_a/sqrt (1.0-$e 2 * sin ($latitude 1) * sin ($latitude 1)); $T = tan ($latitude 1) * TAN ($latitude 1); $C = $ee * cos ($latitude 1) * cos ($latitude 1); $A = ($longitude 1-$longitude 0) * cos ($latitude 1); $M = $_a * ((1-$e 2/4-3 * $e 2 * $e 2/64-5 * $e 2 * $e 2 * $e 2/256) * $latitude 1-(3 * $e 2/8 + 3 * $e 2 * $e 2/3 2 + * $e 2 * $e 2 * $e 2/1024) * SIN (2 * $latitude 1) + (15 * $e 2 * $e 2/256 + * $e 2 * $e 2 * $e 2/1024) * SIN (4 * $latitude 1)-(* $e 2 * $e 2 * $e 2/3072) * SIN (6 * $latitud E1)); $xval = $NN * ($A + (1-$T + $C) * $A * $A * $A/6 + (5-18 * $T + $T * $T + * * $C -58 * $ee) * $A * $A * $A * $A * $A/120); $yval = $M + $NN * TAN ($latitude 1) * ($A * $A/2 + (+ $T + 9 * $C + 4 * $C * $C) * $A * $A * $A * $A/24 + (61-58 * $T + $T * $T + $ * $C -330 * $ee) * $A * $A * $A * $A * $A * $A/720); $X 0 = 1000000 * ($ProjNo + 1) + 500000; $Y 0 = 0; $X = Round (($xval + $X 0) * 100)/100.0; $Y = Round (($yval + $Y 0) * +)/100.0;return Array ($X, $Y);} $LNG = $_get["LNG"); $lat = $_get["lat"]; $XY = Bltoxy ($lat, $LNG); Echo Json_encode ($XY);? >
XY warp Latitude:
<?phpfunction xytobl ($X, $Y) {$_a = 6378245.0; $_f = 1.0/298.3; $zoneWide = 6; $PI = 3.14159265353846; $iPI = 0.0174532925199433; 3.1415926535898/180.0; $ProjNo = Floor ($X/1000000.0); Look for the band number $longitude 0 = ($ProjNo-1) * $zoneWide + $zoneWide/2; $longitude 0 = $longitude 0 * $iPI; Central Meridian $X 0 = $ProjNo * 1000000 + 500000; $Y 0 = 0; $xval = $X-$X 0; $yval = $Y-$Y 0; In-band geodetic coordinates $e 2 = 2 * $_f-$_f * $_F; $e 1 = (1.0-sqrt (1-$e 2))/(1.0 + sqrt (1-$e 2)); $ee = $e 2/(1-$e 2); $M = $yval; $u = $M/($_A * (1-$e 2/4-3 * $e 2 * $e 2/64-5 * $e 2 * $e 2 * $e 2/256)); $fai = $u + (3 * $e $e 1 * $e 1 * $e 1/32) * SIN (2 * $u) + (* $e 1 * $e 1/16-55 * $e 1 * $e 1 * $e 1 * $e 1/ * SIN (4 * $u) + (151 * $e 1 * $e 1 * $e 1/96) * SIN (6 * $u) + (1097 * $e 1 * $e 1 * $e 1 * $e 1/512) * SIN (8 * $u); $C = $ee * cos ($FAI) * cos ($FAI); $T= Tan ($fai) * TAN ($FAI); $NN = $_a/sqrt (1.0-$e 2 * sin ($fai) * sin ($fai)); $R = $_a * (1-$e 2)/sqrt ((1-$e 2 * sin ($fai) * sin ($FAI)) * (1-$e 2 * sin ($fai) * sin ($FAI)) * (1-$e 2 * sin ($FAI) * Sin ($fai))); $D = $xval/$NN; Calculate longitude (longitude) latitude (Latitude) $longitude 1 = $longitude 0 + ($D-(1 + 2 * $T + $C) * $D * $D * $D/6 + (5-2 * $C + * $T-3 * $C * $C + 8 * $ee + * $T * $T) * $D * $D * $D * $D * $D/120)/cos ($FAI); $latitude 1 = $fai-($NN * TAN ($FAI)/$R) * ($D * $D/2-(5 + 3 * $T + ten * $C-4 * $C * $C-9 * $ee) * $D * $D * $D * $D/24 + * $T + 298 * $C + * $T * $T -256 * $ee-3 * $C * $C) * $D * $D * $D * $D * $D * $D/720); Convert to degrees DD $longitude = Round (($longitude 1/$iPI) * 1000000)/1000000.0; $latitude = Round (($latitude 1/$iPI) * 1000000)/1000000.0;return Array ($longitude, $latitude);} $X = $_get["X"]; $Y = $_get["Y"]; $latlng = Xytobl ($X, $Y); Echo Json_encode ($LATLNG);?>