Home >Backend Development >PHP Tutorial >PHP Tencent map longitude and latitude to Baidu map longitude and latitude

PHP Tencent map longitude and latitude to Baidu map longitude and latitude

WBOY
WBOYOriginal
2016-07-25 08:42:331792browse
  1. /**
  2. * China’s normal GCJ02 coordinates---->Baidu Map BD09 coordinates
  3. * Tencent Maps also uses GCJ02 coordinates
  4. * @param double $lat latitude
  5. * @param double $lng longitude
  6. */
  7. function Convert_GCJ02_To_BD09($lat,$lng){
  8. $x_pi = 3.14159265358979324 * 3000 $$0 / $y =
  9. ; z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
  10. $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi) ;
  11. $lng = $z * cos($theta) + 0.0065;
  12. $lat = $z * sin($theta) + 0.006;
  13. return array('lng'=>$lng,'lat'=> $lat);
  14. }
  15. /**
  16. * Baidu Map BD09 coordinates ---->China’s normal GCJ02 coordinates
  17. * Tencent Maps also uses GCJ02 coordinates
  18. * @param double $lat latitude
  19. * @param double $lng longitude
  20. * @return array();
  21. */
  22. function Convert_BD09_To_GCJ02($lat,$lng){
  23. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  24. $x = $lng - 0.0065;
  25. $y = $lat - 0.006;
  26. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
  27. $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
  28. $lng = $z * cos($theta);
  29. $lat = $z * sin($theta);
  30. return array('lng'=>$lng,'lat '=>$lat);
  31. }

PHP
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn