Code Monkey home page Code Monkey logo

convertmc2ll's Introduction

convertMC2LL

将百度地图平面投影坐标(墨卡托)转换为经纬度坐标

用在什么场景

使用PHP来调用百度地图API,某些情况下得到的是投影坐标,需要转换为经纬度坐标

为什么要写这个东西

首先,百度地图最好用
第二,百度接口很不准,搜个西城区的地址给你定位到门头沟去
第三,百度有些隐藏接口非常好用
第四,隐藏接口坐标是投影坐标,需要转换成经纬度坐标
第五,只有百度知道怎么转换
第六,只有百度地图JS文件能看到源码

所以就写了这么个程序来将投影坐标转换为经纬度坐标。当然是根据百度地图js原来来改造的。

使用方法

非常简单

include 'src/Baidumap.php';
$baidu = new Baidumap();
$point = new b4(1294830854, 484857493);
$ll = $baidu->convertMC2LL($point);
var_dump($ll);
#object(b4)#28 (2) { ["lng"]=> float(116.31536904395) ["lat"]=> float(40.071504624032) } 

常用场景举例

需要将用户输入的地址转换成经纬度坐标。百度提了Geocoding API ,但是这个接口太傻,不是地址不存在,就是把昌平的地址定位到门头沟去。

后来发现一个未公开的地址搜索接口 ,这个接口好用,基本上在百度地图首页能搜到的地址这里都能搜到,而且即使你输错了地址也会有一个字段(suggest_query)告诉你正确的地址应该叫什么。

但是这个接口返回的坐标是投影坐标:(1294830854,484857493),这个时候就需要将投影坐标转换为经纬度坐标。

convertmc2ll's People

Contributors

everalan avatar

Stargazers

特大暴学 avatar Orrin avatar  avatar  avatar HUANGWEIBIN avatar  avatar  avatar liushuangxi avatar  avatar  avatar  avatar  avatar

Watchers

 avatar Kang Chen avatar

convertmc2ll's Issues

How and when the conversion works?

Hi @everalan, thanks for your great job on this work.

I'm just curious how you come up with the conversion method, and under which scope/conditions it works?

I tried your code with some of the input like [2000000, 3000000], expected output is [17.966110196716, 26.160794017678] with baidu map APIs, but the result with your program is [26.949165293528, 26.160794017678]

Any information is appreciated! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.