1. Rewrite the batch conversion js provided by Baidu to achieve 100 coordinate points at a time
2.Using recursive callbacks to control the return sequence of coordinate transformations to ensure that a set of coordinates (a set of 100) requested first arrives first
First, let's take a look at two examples of coordinate transformation in the demo of Baidu Maps API:
Convert original coordinates to Baidu coordinates: http://developer.baidu.com/map/jsdemo.htm#a5_2
Batch coordinate conversion: http://developer.baidu.com/map/jsdemo.htm#a5_3
They all use a method BMap.Convertor.translate (pointArr, 0, translateCallback); or a method BMap.Convertor.transMore (pointsArray [posIndex], 0, callback);
They are implemented by two js provided by Baidu: http://developer.baidu.com/map/jsdemo/demo/convertor.js (single coordinate conversion interface) and http://developer.baidu.com/map/jsdemo /demo/changeMore.js (this is a batch conversion interface), where 0 indicates the angular coordinates obtained by the GPS device before conversion, the default type = 4 in the method is the latitude and longitude coordinates used by the Baidu map after conversion, and mode = 1 in the function The representation is a batch conversion, but in fact, we know from the source code that the batch conversion is still subject to a transformation that can only request 20 coordinate points at a time.
So we rewrite the js file provided by Baidu and use its native coordinate conversion api directly: http://developer.baidu.com/map/index.php?title=webapi/guide/changeposition Here is a detailed description of the parameters of this api Explain that it is limited to 100 coordinates at a time. The service address is: http://api.map.baidu.com/geoconv/v1/? For example, we can request this:
var positionUrl = "http://api.map.baidu.com/geoconv/v1/?coords=114.21892734521,29.575429778924;114.21892734521,29.575429778924&from=1&to=5&ak=your key & callback =" + callback;
Below we implement our own batch coordinate transformation (request 100 coordinate points at a time)
Use Baidu Map API to realize batch coordinate conversion of GPS coordinates to Baidu coordinates (such as 1000 points)
For the other functions referenced in the above method, we still use some of the methods provided by Baidu:
Use Baidu Map API to realize batch coordinate conversion of GPS coordinates to Baidu coordinates (such as 1000 points)
2. Use the above coordinate transformation method myTransMore
Suppose testJsonStr might be some location information you want to process, such as an array of json objects like this:
var testJsonStr = [// 1000 data
{"deviceId": "0001", "name": "0001", "longitude": 116.174008, "latitude": 40.059728, "time": "2015-12-18 16:19:51"},
{"deviceId": "0002", "name": "0002", "longitude": 116.172708, "latitude": 40.0603688, "time": "2015-12-18 15:44:36"},
{"deviceId": "0003", "name": "0003", "longitude": 116.174535, "latitude": 40.059727, "time": "2015-12-18 09:31:19"},
...
{"deviceId": "1000", "name": "1000", "longitude": 116.37391967068, "latitude": 39.981656, "time": "2015-12-18 16:59:34"}]
Use a recursive callback to control the order of the data returned after coordinate conversion, so that the data obtained from the coordinate conversion request sent first reaches the program. If there is no control, due to network reasons, it is possible that the data requested for conversion will arrive first. Program, so you do n’t know who responded to the returned data, that is, you ca n’t find the correspondence between the coordinates after correction and the coordinates before correction.
Use Baidu Map API to realize batch coordinate conversion of GPS coordinates to Baidu coordinates (such as 1000 points)
Use Baidu Map API to realize batch coordinate conversion of GPS coordinates to Baidu coordinates (such as 1000 points)
Use Baidu Map API to realize batch coordinate conversion of GPS coordinates to Baidu coordinates (such as 1000 points)