Baidu customers to develop a small program, there is a positioning map display. Baidu small program built api map is not allowed by Baidu, a query to coordinate shift algorithm formula he used in the project, coordinate testing has shown normal phone!
Latitude and longitude coordinates of the pickup by the pickup to Baidu!
.swan file
<map id="myMap" style="width:100%;height:50vh;" longitude="{{longitude}}" latitude="{{latitude}}" scale="16" markers="{{markers}}"></map>
.js file
. 1 Page ({ 2 Data: { . 3 longitude: '120.93032', . 4 Latitude: '30 .804545 ', . 5 markers: [] . 6 }, . 7 the onLoad: function () { . 8 // page load life cycle monitor function . 9 the this. Map_Fn (); 10 }, . 11 the onReady: function () { 12 is // listener initial page rendering is complete lifecycle function 13 is this.mapContext = swan.createMapContext ( 'the myMap'); 14 }, 15 onShow: function () { 16 // lifecycle listener function display page 17 }, 18 onHide: function () { 19 // monitor the life cycle of a function hidden page 20 }, 21 onUnload: function () { 22 // monitor the life cycle of a page unload function 23 }, 24- onPullDownRefresh: function () { 25 // monitor user action pull-down 26 is }, 27 onReachBottom: function () { 28 handler event the pull-bottomed // page 29 }, 30 onShareAppMessage: function () { 31 is // forwarding user clicks on the top right corner 32 }, 33 is Map_Fn: function () { 34 is the let 3.14159265358979324 * PI = 3000.0 / 180.0; 35 let x = this.data.longitude - 0.0065; 36 let y = this.data.latitude - 0.006; 37 let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi); 38 let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi); 39 this.setData({ 40 longitude: z * Math.cos(theta), 41 latitude: z * Math.sin(theta), 42 markers: [ 43 { 44 id: '1', 45 latitude: z * Math.sin(theta), 46 longitude: z * Math.cos(theta), 47 iconPath: '/images/api_logo.png', 48 callout: { 49 the display: 'ALWAYS', 50 Content: 'Peacock City Jiashan Xitang 1' 51 } // display in real machine 52 } 53 ] 54 }); 55 the console.log ( "longitude calculated after the" + X); 56 is the console.log ( "after computing the latitude" + Y); 57 is } 58 });
Reference URL: https: //blog.csdn.net/coolypf/article/details/8569813