zoukankan      html  css  js  c++  java
  • OpenStreetMap、googleMap等经纬度和行列号之间相互转化(python,JavaScript,php,Java,C#等)

    python:
    # OpenStreetMap经纬度转行列号
    def deg2num(lat_deg, lon_deg, zoom):
      lat_rad = math.radians(lat_deg)
      n = 2.0 ** zoom
      xtile = int((lon_deg + 180.0) / 360.0 * n)
      ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
      return (xtile, ytile)
    
    # OpenStreetMap行列号转经纬度
    def num2deg(xtile, ytile, zoom):
      n = 2.0 ** zoom
      lon_deg = xtile / n * 360.0 - 180.0
      lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * ytile / n)))
      lat_deg = math.degrees(lat_rad)
      return (lat_deg, lon_deg)
    
    # 验证可用
    print deg2num(34.972,114.953,13)
    # print num2deg(105207,52262,17)
    View Code
    javascript:
    
    function long2tile(lon,zoom) { return (Math.floor((lon+180)/360*Math.pow(2,zoom))); }
     function lat2tile(lat,zoom)  { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); }
    
    
    function tile2long(x,z) {
      return (x/Math.pow(2,z)*360-180);
     }
     function tile2lat(y,z) {
      var n=Math.PI-2*Math.PI*y/Math.pow(2,z);
      return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n))));
     }

    更多语言方法参考这里

  • 相关阅读:
    this.$nextTick()的原理与使用场景
    vue中通过方法返回data中的对象是这个{__ob__: Observer}
    3月23日学习日志
    3月22日学习日志
    3月19日学习日志
    3月18日学习日志
    3月17日学习日志
    3月16日学习日志
    3月15日学习日志
    3月12日学习日志
  • 原文地址:https://www.cnblogs.com/Micang/p/6346446.html
Copyright © 2011-2022 走看看