V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
pc10201
V2EX  ›  Python

如何用python实现百度地图墨卡托坐标跟经纬度坐标互转?

  •  
  •   pc10201 · 2014-01-01 18:13:18 +08:00 · 11769 次点击
    这是一个创建于 3739 天前的主题,其中的信息可能已经有所发展或是发生改变。
    从百度地图的js中获取到了一部分数据

    "name":"多味小吃店(荣华东道)","overall_rating":"3.5","pc_bookable":0,"phone":"(021)62088786","poi_address":"上海长宁区荣华东道19弄1楼3号C室(近水城南路)","point":{"x":13514570.1,"y":3636377.2},"price":"40","service_rating":"3","shop_hours_flag":1,"tag":"美食,韩国料理,古北","wap_bookable":0},"src_name":"cater"}

    里面的point":{"x":13514570.1,"y":3636377.2}数据转换成坐标即是
    121.39532, 31.19393

    如何用python实现百度地图墨卡托坐标跟经纬度坐标互转?
    最好是不用百度的API,直接计算
    8 条回复    1970-01-01 08:00:00 +08:00
    zavior
        1
    zavior  
       2014-01-01 20:11:42 +08:00
    其实。。这样转换违反国家相关法律
    est
        2
    est  
       2014-01-01 20:16:38 +08:00
    lazycat
        3
    lazycat  
       2014-01-02 00:01:56 +08:00 via Android
    @zavior 为什么。。。
    dancingbear
        4
    dancingbear  
       2014-01-02 00:09:40 +08:00
    没有这样的逆向算法吧
    zavior
        5
    zavior  
       2014-01-02 13:45:57 +08:00
    @lazycat 因为奇葩天朝法律规定,地图的坐标必须有偏移,任何从火星坐标转换回地球坐标的行为都是违法的。
    phyng
        6
    phyng  
       2014-01-02 21:46:31 +08:00
    import math

    mercator = {"x":13514570.1, "y":3636377.2}
    lonlat = {}

    x = mercator['x']/ 20037508.3427892 * 180
    y = mercator['y']/ 20037508.3427892 * 180

    lonlat['x'] = x
    lonlat['y'] = 180 / math.pi * (2 * math.atan(math.exp(y * math.pi / 180)) - math.pi / 2)

    print lonlat

    这样得到的结果是{'y': 31.027932178384102, 'x': 121.40344879134716}
    有误差可能出在20037508.3427892以及math.pi

    偏移问题不是指这个,偏移是实际坐标要经过我朝保密插件处理成假坐标,而墨卡托坐标跟经纬度坐标互转是有公开算法的对地球的不同表示。参考http://www.cnblogs.com/liongg/archive/2009/04/20/1439905.html
    http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=78245
    pc10201
        7
    pc10201  
    OP
       2014-01-03 09:22:01 +08:00
    @phyng "point":{"x":13514570.1,"y":3636377.2}请问这个坐标到底是国际的墨卡托坐标还是我朝加密后的火星坐标?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1037 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:18 · PVG 03:18 · LAX 12:18 · JFK 15:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.