Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call Baidu Map API to realize coordinate Transformation

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to call Baidu Map API to achieve coordinate transformation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Python code

Because different maps use different latitude and longitude coordinates (for example, Baidu maps use Baidu coordinates, Gaud, Google, etc., use GCJ-02 coordinates), different coordinates need to be transformed in practical application, otherwise the points of latitude and longitude of Baidu will be painted on Amap, and the position will shift.

There are two ways to realize the transformation from Baidu coordinates to Gaud coordinates. One is like calling Baidu Map API, which calls Gaud API interface to realize coordinate transformation, and the other can be converted directly through calculation.

Call Gaud API API

The Gaode open platform is https://lbs.amap.com/api/webservice/summary, which is the same as calling Baidu API. Users need to apply for their own ak and pass it as a required parameter before the call can be completed. # convert Baidu latitude and longitude to Gaud longitude and latitude def getGCJ02 (lng,lat) through web api: url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?coordsys=baidu&output=json&key=' ak =' your ak' # generate complete url uri = url + ak +'& locations=' + str (lng) +','+ str (lat) html = requests.get (uri) # get web content bs_getDetail = BeautifulSoup (html.text 'lxml') # parse the web page # find the text that stores longitude and latitude data Convert it to a dictionary and get the corresponding longitude and latitude location = eval (bs_getDetail.p.text) ["locations"] return location to calculate directly.

The relevant results can also be obtained by direct calculation. Here, note that the math library should be loaded in advance.

# convert Baidu longitude and latitude into Gaud longitude and latitude def getGCJ02_2 (lng, lat): PI = math.pi * 3000.0 / 180.0; x = lng-0.0065; y = lat-0.006; z = math.sqrt (x * x + y * y)-0.00002 * math.sin (y * PI); theta = math.atan2 (y, x)-0.000003 * math.cos (x * PI) Gg_lng = z * math.cos (theta); gg_lat = z * math.sin (theta); return str (list ([gg_lng, gg_lat])) the final result is as follows: the front is Baidu latitude and longitude coordinates, followed by the converted Gaud longitude and latitude coordinates: [120.3009283509351130.429908332211145]-> [120.2943448753952,30.424254963690057]

Thank you for reading this article carefully. I hope the article "how to use Baidu Map API to realize coordinate transformation" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report