地球坐标转高德的火星坐标

<?php
class Point {
    private $longitude;
    private $latitude;
    private $x;
    private $y;
    public function setX( $x ) {
        $this->x = $x;
    }
    public function getX() {
        return $this->x;
    }
    public function setY( $y ) {
        $this->y = $y;
    }
    public function getY() {
        return $this->y;
    }
    public function setLongitude( $longitude ) {
        $this->longitude = $longitude;
    }
    public function setLatitude( $latitude ) {
        $this->latitude = $latitude;
    }
    public function getLongitude() {
        return $this->longitude;
    }
    public function getLatitude() {
        return $this->latitude;
    }
}
class Converter {
    public $casm_rr = 0;
    public $casm_t1 = 0;
    public $casm_t2 = 0;
    public $casm_x1 = 0;
    public $casm_y1 = 0;
    public $casm_x2 = 0;
    public $casm_y2 = 0;
    public $casm_f = 0;
    public function __construct() {
        $this->casm_rr = 0;
        $this->casm_t1 = 0;
        $this->casm_t2 = 0;
        $this->casm_x1 = 0;
        $this->casm_y1 = 0;
        $this->casm_x2 = 0;
        $this->casm_y2 = 0;
        $this->casm_f = 0;
    }
    public function getEncryPoint( $x, $y ) {
        $point = new Point();
        $x1;
        $tempx;
        $y1;
        $tempy;
        $x1 = $x * 3686400.0;
        $y1 = $y * 3686400.0;
        $gpsWeek = 0;
        $gpsWeekTime = 0;
        $gpsHeight = 0;
        $point = $this->wgtochina_lb( 1, (int)$x1, (int)$y1, (int)$gpsHeight, (int)$gpsWeek, (int)$gpsWeekTime );
        $tempx = $point->getX();
        $tempy = $point->getY();
        $tempx = $tempx / 3686400.0;
        $tempy = $tempy / 3686400.0;
        $point = new Point();
        $point->setX( $tempx );
        $point->setY( $tempy );
        return $point;
    }
    protected function yj_sin2( $x ) {
        $tt;
        $ss;
        $ff;
        $s2;
        $cc;
        $ff = 0;
        if ( $x < 0 ) {
            $x = -$x;
            $ff = 1;
        }
        $cc = (int)($x / 6.28318530717959);
        $tt = $x - $cc * 6.28318530717959;
        if ( $tt > 3.1415926535897932 ) {
            $tt = $tt - 3.1415926535897932;
            if ( $ff == 1 ) {
                $ff = 0;
            }
            else if ( $ff == 0 ) {
                $ff = 1;
            }
        }
        $x = $tt;
        $ss = $x;
        $s2 = $x;
        $tt = $tt * $tt;
        $s2 = $s2 * $tt;
        $ss = $ss - $s2 * 0.166666666666667;
        $s2 = $s2 * $tt;
        $ss = $ss + $s2 * 8.33333333333333E-03;
        $s2 = $s2 * $tt;
        $ss = $ss - $s2 * 1.98412698412698E-04;
        $s2 = $s2 * $tt;
        $ss = $ss + $s2 * 2.75573192239859E-06;
        $s2 = $s2 * $tt;
        $ss = $ss - $s2 * 2.50521083854417E-08;
        if ( $ff == 1 ) {
            $ss = -$ss;
        }
        return $ss;
    }
    protected function Transform_yj5( $x, $y ) {
        $tt;
        $tt = 300 + 1 * $x + 2 * $y + 0.1 * $x * $x + 0.1 * $x * $y + 0.1 * sqrt( sqrt( $x * $x ) );
        $tt = $tt + ( 20 * $this->yj_sin2( 18.849555921538764 * $x ) + 20 * $this->yj_sin2( 6.283185307179588 * $x ) ) * 0.6667;
        $tt = $tt + ( 20 * $this->yj_sin2( 3.141592653589794 * $x ) + 40 * $this->yj_sin2( 1.047197551196598 * $x ) ) * 0.6667;
        $tt = $tt + ( 150 * $this->yj_sin2( 0.2617993877991495 * $x ) + 300 * $this->yj_sin2( 0.1047197551196598 * $x ) ) * 0.6667;
        return $tt;
    }
    protected function Transform_yjy5( $x, $y ) {
        $tt;
        $tt = -100 + 2 * $x + 3 * $y + 0.2 * $y * $y + 0.1 * $x * $y + 0.2 * sqrt( sqrt( $x * $x ) );
        $tt = $tt + ( 20 * $this->yj_sin2( 18.849555921538764 * $x ) + 20 * $this->yj_sin2( 6.283185307179588 * $x ) ) * 0.6667;
        $tt = $tt + ( 20 * $this->yj_sin2( 3.141592653589794 * $y ) + 40 * $this->yj_sin2( 1.047197551196598 * $y ) ) * 0.6667;
        $tt = $tt + ( 160 * $this->yj_sin2( 0.2617993877991495 * $y ) + 320 * $this->yj_sin2( 0.1047197551196598 * $y ) ) * 0.6667;
        return $tt;
    }
    protected function Transform_jy5( $x, $xx ) {
        $n;
        $a;
        $e;
        $a = 6378245;
        $e = 0.00669342;
        $n = sqrt( 1 - $e * $this->yj_sin2( $x * 0.0174532925199433 ) * $this->yj_sin2( $x * 0.0174532925199433 ) );
        $n = ( $xx * 180) / ( $a / $n * cos( $x * 0.0174532925199433 ) * 3.1415926 );
        return $n;
    }
    protected function Transform_jyj5( $x, $yy ) {
        $m;
        $a;
        $e;
        $mm;
        $a = 6378245;
        $e = 0.00669342;
        $mm = 1 - $e * $this->yj_sin2( $x * 0.0174532925199433) * $this->yj_sin2( x * 0.0174532925199433 );
        $m = ( $a * ( 1 - $e ) ) / ( $mm * sqrt( $mm ) );
        return ( $yy * 180 ) / ( $m * 3.1415926 );
    }
    protected function r_yj() {
        $casm_a = 314159269;
        $casm_c = 453806245;
        return 0;
    }
    protected function random_yj() {
        $t;
        $casm_a = 314159269;
        $casm_c = 453806245;
        $this->casm_rr = $casm_a * $this->casm_rr + $casm_c;
        $t = (int)( $this->casm_rr / 2 );
        $this->casm_rr = $this->casm_rr - $t * 2;
        $this->casm_rr = $this->casm_rr / 2;
        return ( $this->casm_rr );
    }
    protected function IniCasm( $w_time, $w_lng, $w_lat ) {
        $tt;
        $this->casm_t1 = $w_time;
        $this->casm_t2 = $w_time;
        $tt = (int)( $w_time / 0.357 );
        $this->casm_rr = $w_time - $tt * 0.357;
        if ( $w_time == 0 )
            $this->casm_rr = 0.3;
        $this->casm_x1 = $w_lng;
        $this->casm_y1 = $w_lat;
        $this->casm_x2 = $w_lng;
        $this->casm_y2 = $w_lat;
        $this->casm_f = 3;
    }
    protected function wgtochina_lb( $wg_flag, $wg_lng, $wg_lat, $wg_heit, $wg_week, $wg_time ) {
        $x_add;
        $y_add;
        $h_add;
        $x_l;
        $y_l;
        $casm_v;
        $t1_t2;
        $x1_x2;
        $y1_y2;
        $point = new Point();
        if ( $wg_heit > 5000 ) {
            return $point;
        }
        $x_l = $wg_lng;
        $x_l = $x_l / 3686400.0;
        $y_l = $wg_lat;
        $y_l = $y_l / 3686400.0;
        if ( $x_l < 72.004 ) {
            return $point;
        }
        if ( $x_l > 137.8347) {
            return $point;
        }
        if ( $y_l < 0.8293 ) {
            return $point;
        }
        if ( $y_l > 55.8271 ) {
            return $point;
        }
        if ( $wg_flag == 0 ) {
            $this->IniCasm( $wg_time, $wg_lng, $wg_lat );
            $point = new Point();
            $point->setLatitude( $wg_lng );
            $point->setLongitude( $wg_lat );
            return $point;
        }
        $this->casm_t2 = $wg_time;
        $t1_t2 = ( $this->casm_t2 - $this->casm_t1 ) / 1000.0;
        if ( $t1_t2 <= 0 ) {
            $this->casm_t1 = $this->casm_t2;
            $this->casm_f = $this->casm_f + 1;
            $this->casm_x1 = $this->casm_x2;
            $this->casm_f = $this->casm_f + 1;
            $this->casm_y1 = $this->casm_y2;
            $this->casm_f = $this->casm_f + 1;
        }
        else {
            if ( $t1_t2 > 120 )
            {
                if ($this->casm_f == 3)
                {
                    $this->casm_f = 0;
                    $this->casm_x2 = $wg_lng;
                    $this->casm_y2 = $wg_lat;
                    $x1_x2 = $this->casm_x2 - $this->casm_x1;
                    $y1_y2 = $this->casm_y2 - $this->casm_y1;
                    $casm_v = sqrt( $x1_x2 * $x1_x2 + $y1_y2 * $y1_y2 ) / t1_t2;
                    if ( $casm_v > 3185 )
                    {
                        return $point;
                    }
                }
                $this->casm_t1 = $this->casm_t2;
                $this->casm_f = $this->casm_f + 1;
                $this->casm_x1 = $this->casm_x2;
                $this->casm_f = $this->casm_f + 1;
                $this->casm_y1 = $this->casm_y2;
                $this->casm_f = $this->casm_f + 1;
            }
        }
        $x_add = $this->Transform_yj5( $x_l - 105, $y_l - 35 );
        $y_add = $this->Transform_yjy5( $x_l - 105, $y_l - 35 );
        $h_add = $wg_heit;
        $x_add = $x_add + $h_add * 0.001 + $this->yj_sin2( $wg_time * 0.0174532925199433 ) + $this->random_yj();
        $y_add = $y_add + $h_add * 0.001 + $this->yj_sin2( $wg_time * 0.0174532925199433 ) + $this->random_yj();
        $point = new Point();
        $point->setX( ( ( $x_l + $this->Transform_jy5( $y_l, $x_add ) ) * 3686400 ) );
        $point->setY( ( ( $y_l + $this->Transform_jyj5( $y_l, $y_add ) ) * 3686400 ) );
        return $point;
    }
    protected function isValid( $validdays ) {
        //long standand = 1253525356;
        $h = 3600;
        $currentTime = new DateTime();
        if( $currentTime.getTimestamp() / 1000 - 1253525356 >= $validdays * 24 * $h ) {
            return false;
        }
        else {
            return true;
        }
    }
    protected function getEncryCoord( $coord, $flag ) {
        if ( $flag )  {
            $xy = $coord.split(",");
            $x = (Double)($xy[0]);
            $y = (Double)($xy[1]);
            $point = new Point();
            $x1;
            $tempx;
            $y1;
            $tempy;
            $x1 = $x * 3686400.0;
            $y1 = $y * 3686400.0;
            $gpsWeek = 0;
            $gpsWeekTime = 0;
            $gpsHeight = 0;
            $point = $this->wgtochina_lb( 1, (int)$x1, (int)$y1, (int)$gpsHeight, (int)$gpsWeek, (int)$gpsWeekTime );
            $tempx = $point->getX();
            $tempy = $point->getY();
            $tempx = $tempx / 3686400.0;
            $tempy = $tempy / 3686400.0;
            return $tempx + "," + $tempy;
        }
        else
        {
            return "";
        }
    }
}
时间: 2024-08-27 16:02:36

地球坐标转高德的火星坐标的相关文章

[转]地球坐标 火星坐标 百度坐标 相互转换

在开始这个题目之前,先给大家再次扫扫盲,扫的不是坐标系统的盲,而是我们国家所使用的坐标系统.大家都知道,美国GPS使用的是WGS84的坐标系统,以经纬度的形式来表示地球平面上的某一个位置,这应该是国际共识.但在我国,出于国家安全考虑,国内所有导航电子地图必须使用国家测绘局制定的加密坐标系统,即将一个真实的经纬度坐标加密成一个不正确的经纬度坐标,我们在业内将前者称之为地球坐标,后者称之为火星坐标,具体的说明可以参看百度百科中关于火星坐标系统的解释. 1.国内各地图API坐标系统比较 参考http:

[C#]利用纠偏数据来处理地球坐标(WGS-84)与火星坐标 (GCJ-02)转换

关键代码: using System; using System.Collections; using System.Collections.Generic; using System.IO; using YanZhiwei.DotNet2.Utilities.Models; namespace YanZhiwei.DotNet2.Utilities.Common { /// <summary> /// 地图纠偏数据帮助类 /// </summary> public class M

iOS 火星坐标相关整理及解决方案汇总(转)

这几天在处理定位相关的代码,彻彻底底的被火星坐标恶心到了. 恶心列表 从 CLLocationManager 取出来的经纬度放到 mapView 上显示,是错的! 从 CLLocationManager 取出来的经纬度去 Google Maps API 做逆地址解析,当然是错的! 从 MKMapView 取出来的经纬度去 Google Maps API 做逆地址解析终于对了.去百度地图API做逆地址解析,依旧是错的! 从上面两处取的经纬度放到百度地图上显示都是错的!错的!的! 当时我还不知道火星

百度坐标转火星坐标

下面是百度官方对百度坐标为何有偏移的解释:国际经纬度坐标标准为WGS-84,国内必须至少使用国测局制定的GCJ-02,对地理位置进行首次加密.百度坐标在此基础上,进行了BD-09二次加密措施,更加保护了个人隐私. 百度对外接口的坐标系并不是GPS采集的真实经纬度,需要通过坐标转换接口进行转换 API:坐标系 百度地图API:百度坐标 腾讯搜搜地图API:火星坐标 搜狐搜狗地图API:搜狗坐标* 阿里云地图API:火星坐标 图吧MapBar地图API:图吧坐标 高德MapABC地图API:火星坐标

百度 Google 全国 地图 火星坐标 产生原因(记录)

1.偏移的起因:天朝测绘局以国家安全为理由,用法律的形式对所有在天朝发行的地图类产品加了强制性规范,要求所有地图类产品都必须使用国家测绘局的一种加偏移的算法,对地图的真实坐标进行加偏移处理,之后才可能通过审批准许上市.因此,天朝的所有官方及商用地图的坐标都是偏移的,这种偏移属于非线性的,偏移量在300至500米不等,偏移方向也不定.这种加过偏移的地图坐标就是所谓"火星坐标".2.GPS接收机本身接收卫星的信号,计算出本机所在位置的经纬度,在没有做特别处理的时候,这个经纬度是正确的.但是

地图坐标转换 -- 火星坐标与GPS坐标

第一次处理地理位置的数据的人,没什么经验,往往掉入很多坑浪费不少时间.我也是刚刚从坑里爬出来.这篇博文主要是把入门GPS轨迹分析的经验总结一下,以方便大家少走些弯路. (1)可视化 GPS 路径 刚拿到一堆GPS轨迹数据,想看看它长什么样?于是先想办法把它们可视化出来.有很多地图的API可以用,如果不是想搞演示,只是为了快速随便看一眼的话,推荐用百度的在线示例API  http://developer.baidu.com/map/jsdemo.htm#c1_3  里面有比较详细的例子,很丰富的操

[转]百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换

注:项目中面对不同的坐标体系,在地图上显示会有不小的偏差,下面是JavaScript的转换方法. //定义一些常量 var x_PI = 3.14159265358979324 * 3000.0 / 180.0; var PI = 3.1415926535897932384626; var a = 6378245.0; var ee = 0.00669342162296594323; /** * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换 * 即 百度 转 谷歌.高德 *

火星坐标、百度坐标、WGS84坐标转换代码(JS版)

/** * 提供了百度坐标(BD09).国测局坐标(火星坐标,GCJ02).和WGS84坐标系之间的转换 */ //定义一些常量 var x_PI = 3.14159265358979324 * 3000.0 / 180.0; var PI = 3.1415926535897932384626; var a = 6378245.0; var ee = 0.00669342162296594323; /** * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换 * 即 百度 转

百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换(JS版代码)

/** * Created by Wandergis on 2015/7/8. * 提供了百度坐标(BD09).国测局坐标(火星坐标,GCJ02).和WGS84坐标系之间的转换 */ //定义一些常量 var x_PI = 3.14159265358979324 * 3000.0 / 180.0; var PI = 3.1415926535897932384626; var a = 6378245.0; var ee = 0.00669342162296594323; /** * 百度坐标系 (