├── AMap.qml ├── MapSearchItem.qml ├── QAMap.pro ├── README.md ├── amap.js ├── fontawesome ├── FontAwesome.otf ├── FontAwesome.qml └── awesome.js ├── main.cpp ├── main.qml ├── qml.qrc └── transform.js /AMap.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | import QtLocation 5.9 3 | import QtPositioning 5.6 4 | import QtQuick.Controls 2.2 5 | import "amap.js" as AMAP_API 6 | import "transform.js" as Transform 7 | import "fontawesome"// as FontAwesome 8 | Map { 9 | id: map 10 | width: 100; height: 100 11 | zoomLevel: 18 12 | center: QtPositioning.coordinate(22.5574462,113.9449748) 13 | // Behavior on center { 14 | // CoordinateAnimation { 15 | // duration: 1000 16 | // easing.type: Easing.Linear} 17 | // } 18 | 19 | // if(googleMap.plugin.name == Transform.transformMapName) 20 | // {//GoogleMap.GPS.gcj_encrypt(data_json.Lat, data_json.Lon)// 21 | // var gmap = Transform.wgs2gcj(lat,lon) 22 | // lat = gmap.lat 23 | // lon = gmap.lon 24 | // } 25 | 26 | // Address{} 27 | 28 | function testWeather(){ 29 | AMAP_API.getWeatherInfo("深圳", function(info){ 30 | console.debug(info.lives[0].province 31 | +info.lives[0].city + "\n" 32 | +"天气:"+info.lives[0].weather + "\n" 33 | +"温度:"+info.lives[0].temperature+"度\n" 34 | +info.lives[0].winddirection + info.lives[0].windpower + "级\n" 35 | +"湿度:" + info.lives[0].humidity) 36 | }) 37 | } 38 | 39 | function testAutoGrasp(){ 40 | console.debug(Date()) 41 | var infos = new Array 42 | console.debug() 43 | infos.push({location:"113.944037,22.556817",time: Math.floor(Date.now()/1000),direction:"1",speed:"1"}) 44 | infos.push({location:"113.943425,22.556732",time: Math.floor(1+Date.now()/1000),direction:"1",speed:"1"}) 45 | infos.push({location:"113.942438,22.556985",time: Math.floor(3+Date.now()/1000),direction:"2",speed:"2"}) 46 | AMAP_API.getAutoGrasp(infos,function(grasp){ 47 | console.debug("grasp",grasp.info, JSON.stringify(grasp)) 48 | for(var i in grasp.roads){ 49 | console.debug("G:",grasp.roads[i].roadname, grasp.roads[i].crosspoint) 50 | 51 | } 52 | }) 53 | } 54 | 55 | function testDrivingDirection(){ 56 | var origin="",destination="" 57 | AMAP_API.getGeoCode("宝安公园西二门","深圳", function(geo){ 58 | for(var i in geo.geocodes){ 59 | origin = geo.geocodes[i].location 60 | // console.debug() 61 | // var location = geo.geocodes[i].location.split(",") 62 | // testItem.center.latitude = location[1] 63 | // testItem.center.longitude = location[0] 64 | // map.center = testItem.center 65 | AMAP_API.getGeoCode("华瀚科技","深圳", function(geo){ 66 | for(var i in geo.geocodes){ 67 | destination = geo.geocodes[i].location 68 | //// console.debug() 69 | // var location = geo.geocodes[i].location.split(",") 70 | // testItem.center.latitude = location[1] 71 | // testItem.center.longitude = location[0] 72 | // map.center = testItem.center 73 | AMAP_API.getDrivingDirection(origin, destination, function(driving){ 74 | // console.debug("driving.info",origin, destination) 75 | 76 | var steps = driving.route.paths[0].steps 77 | routeLine.addCoordinate(origin.split(",")[1],origin.split(",")[0]) 78 | for (var i in steps){ 79 | // console.debug(steps[i].instruction) 80 | var polylinepoints = steps[i].polyline.split(";") 81 | for(var j in polylinepoints){ 82 | 83 | var point = polylinepoints[j].split(",") 84 | // console.debug(point[1], ",",point[0]) 85 | routeLine.addCoordinate(QtPositioning.coordinate(point[1],point[0])) 86 | }// 87 | } 88 | routeLine.addCoordinate(destination.split(",")[1],destination.split(",")[0]) 89 | originItem.center = routeLine.path[0] 90 | destinationItem.center = routeLine.path[routeLine.path.length-1] 91 | }) 92 | } 93 | }) 94 | } 95 | }) 96 | } 97 | activeMapType: map.supportedMapTypes[10] 98 | plugin: Plugin{ 99 | name: "esri"//"amap"//"googlemaps" 100 | Component.onCompleted: { 101 | console.debug(availableServiceProviders,preferred) 102 | testWeather() 103 | testDrivingDirection() 104 | testAutoGrasp() 105 | console.debug("supportedMapTypes:--------------------------------") 106 | for(var i in map.supportedMapTypes) 107 | { 108 | console.debug("|-->",i,map.supportedMapTypes[i].description,"->" 109 | ,map.supportedMapTypes[i].mobile,"->" 110 | ,map.supportedMapTypes[i].name) 111 | } 112 | console.debug("--------------------------------------------------") 113 | } 114 | } 115 | 116 | // onWidthChanged: AMAP_API.width = width 117 | // onHeightChanged: AMAP_API.height =height 118 | // onZoomLevelChanged: AMAP_API.zoom = Math.floor(zoomLevel) 119 | onCenterChanged: { 120 | AMAP_API.latitude = center.latitude 121 | AMAP_API.longitude = center.longitude 122 | // amapImage.source = AMAP_API.getAMapSource() 123 | } 124 | 125 | // Image { 126 | // id: amapImage 127 | // anchors.fill: parent 128 | // } 129 | 130 | MapPolyline{ 131 | id: routeLine 132 | line.width: 6 133 | line.color: "#46a2da" 134 | } 135 | MapCircle { 136 | id: originItem 137 | color: "blue" 138 | radius: 24-map.zoomLevel 139 | } 140 | MapCircle { 141 | id: destinationItem 142 | color: "blue" 143 | radius: 24-map.zoomLevel 144 | } 145 | 146 | function addSearchItem(tips){ 147 | searchComboBox.updataModel(tips) 148 | // console.debug("Tips", JSON.stringify(tips)) 149 | for(var i in tips){ 150 | // console.debug(tips[i].name,JSON.stringify(tips[i])) 151 | if("" == tips[i].location) continue 152 | var point = (tips[i].location).split(",") 153 | var component = Qt.createComponent("qrc:/MapSearchItem.qml"); 154 | 155 | if (component.status == Component.Ready){ 156 | 157 | var search_item = component.createObject(map, {"name":tips[i].name,"index": (parseInt(i)+1), 158 | "coordinate": QtPositioning.coordinate(point[1], point[0])}); 159 | map.addMapItem(search_item) 160 | 161 | } 162 | 163 | 164 | // mapCircleObject.center = QtPositioning.coordinate(point[1],point[0]) 165 | // map.addMapItem(mapCircleObject) 166 | // map.center = mapCircleObject.center 167 | } 168 | 169 | } 170 | 171 | ComboBox{ 172 | id: searchComboBox 173 | anchors.fill: searchTextField 174 | textRole: "name" 175 | onCurrentTextChanged: searchTextField.text = currentText 176 | function updataModel(data){ 177 | model = data 178 | popup.open() 179 | map.clearMapItems() 180 | } 181 | } 182 | TextField{ 183 | id: searchTextField 184 | placeholderText: qsTr("搜索位置、公交、地铁站") 185 | text: "松坪山" 186 | onAccepted: { 187 | AMAP_API.getInputtips(searchTextField.text, function(tips){ 188 | addSearchItem(tips.tips) 189 | }) 190 | } 191 | FontAwesome{ 192 | name: "search" 193 | anchors.verticalCenter: parent.verticalCenter 194 | anchors.right: parent.right 195 | anchors.rightMargin: 8 196 | color: searchIconArea.containsMouse ? "#46a2da" : "grey" 197 | MouseArea{ 198 | id: searchIconArea 199 | hoverEnabled: true 200 | anchors.fill: parent 201 | onClicked:{ 202 | AMAP_API.getInputtips(searchTextField.text, function(tips){ 203 | // console.debug("Tips",tips.info, JSON.stringify(tips)) 204 | addSearchItem(tips.tips) 205 | }) 206 | } 207 | } 208 | } 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /MapSearchItem.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | import QtLocation 5.9 3 | import QtPositioning 5.6; 4 | import "fontawesome" 5 | MapQuickItem { 6 | property string name: "" 7 | property int index: 0 8 | anchorPoint: Qt.point(32,32) 9 | sourceItem: Item { 10 | width: 64; height: 64 11 | Text { 12 | visible: itemArea.containsMouse 13 | text: qsTr(name) 14 | color: "#46a2da" 15 | font.pixelSize: 12 16 | horizontalAlignment: Text.AlignHCenter 17 | } 18 | FontAwesome{ 19 | name: "map_marker" 20 | color: "red" 21 | font.pixelSize: 54 22 | anchors.horizontalCenter: parent.horizontalCenter 23 | anchors.bottom: parent.bottom 24 | Text { 25 | anchors.fill: parent 26 | text: qsTr(index.toString()) 27 | color: "#46a2da" 28 | font.pixelSize: 24 29 | verticalAlignment: Text.AlignVCenter 30 | horizontalAlignment: Text.AlignHCenter 31 | } 32 | } 33 | MouseArea{ 34 | id: itemArea 35 | anchors.fill: parent 36 | hoverEnabled: true 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /QAMap.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 调用高德地图api进行地图纠偏demo 2 | 3 | -------------------------------------------------------------------------------- /amap.js: -------------------------------------------------------------------------------- 1 | var amap_key = "341c6d9e9840212d799314a326a44857" 2 | var car_id = "abcd123456" 3 | var width = 200 4 | var height = 200 5 | var zoom = 10 6 | var latitude = 22.5574462 7 | var longitude = 113.9449748 8 | 9 | function sendXMLHttpRequest(url, callback){ 10 | var req = new XMLHttpRequest; 11 | req.open("GET",url); 12 | req.onreadystatechange = function() { 13 | var status = req.readyState; 14 | if (status === XMLHttpRequest.DONE) { 15 | // var objectArray = JSON.parse(req.responseText); 16 | // console.debug(req.responseText) 17 | callback(JSON.parse(req.responseText)); 18 | } 19 | } 20 | req.send(); 21 | } 22 | 23 | //http://restapi.amap.com/v3/staticmap?location=116.481485,39.990464&zoom=10&size=750*300&traffic=1&key=341c6d9e9840212d799314a326a44857 24 | //http://restapi.amap.com/v3/staticmap?location=22.5750427,113.92297&zoom=7&size=180*120&traffic=1&key=341c6d9e9840212d799314a326a44857 25 | //静态地图 26 | function getAMapSource() { 27 | var url = "http://restapi.amap.com/v3/staticmap?location=" 28 | url += longitude +","+ latitude 29 | url += "&zoom="+ zoom 30 | url += "&size="+width+"*"+height 31 | url += "&traffic=1" 32 | url += "&key=" + amap_key 33 | return url 34 | } 35 | // AMAP_API.getGeoCode("流塘路口","深圳", function(geo){ 36 | // for(var i in geo.geocodes){ 37 | // console.debug() 38 | // var location = geo.geocodes[i].location.split(",") 39 | // testItem.center.latitude = location[1] 40 | // testItem.center.longitude = location[0] 41 | // map.center = testItem.center 42 | // } 43 | // }) 44 | function getGeoCode(address, city, callback){ 45 | var url = "http://restapi.amap.com/v3/geocode/geo?key=" + amap_key 46 | url += "&address="+ address+"&city="+city 47 | sendXMLHttpRequest(url,callback) 48 | } 49 | //抓路服务 50 | // AMAP_API.locations_info.push({location:"116.496167,39.917066",time:"1434077500",direction:"1",speed:"1"}) 51 | // AMAP_API.locations_info.push({location:"116.496149,39.917205",time:"1434077501",direction:"1",speed:"1"}) 52 | // AMAP_API.locations_info.push({location:"116.496149,39.917326",time:"1434077510",direction:"2",speed:"2"}) 53 | // AMAP_API.getAutoGrasp(function(grasp){ 54 | // console.debug("grasp",grasp.info) 55 | // for(var i in grasp.roads){ 56 | // console.debug("G:",grasp.roads[i].roadname, grasp.roads[i].crosspoint) 57 | // } 58 | // }) 59 | var locations_info = new Array 60 | //AMAP_API.locations_info.push({location:"116.496167,39.917066",time:"1434077500",direction:"1",speed:"1"}) 61 | function getAutoGrasp(infos,callback){ 62 | 63 | var locations="", time="", direction="", speed="" 64 | 65 | for(var i in infos) 66 | { 67 | locations += infos[i].location + "|" 68 | time += infos[i].time + "," 69 | direction += infos[i].direction + "," 70 | speed += infos[i].speed + "," 71 | } 72 | locations = locations.substring(0, locations.lastIndexOf('|')); 73 | time = time.substring(0, time.lastIndexOf(',')); 74 | direction = direction.substring(0, direction.lastIndexOf(',')); 75 | speed = speed.substring(0, speed.lastIndexOf(',')); 76 | 77 | var url = "http://restapi.amap.com/v3/autograsp?key=" + amap_key 78 | url += "&carid=" + car_id 79 | url += "&locations=" + locations 80 | url += "&time=" + time 81 | url += "&direction=" + direction 82 | url += "&speed=" + speed 83 | console.debug(url) 84 | sendXMLHttpRequest(url,callback) 85 | locations.length = 0 86 | } 87 | 88 | //路径规划--驾车路径规划 89 | // var origin="116.481028,39.989643",destination="116.434446,39.90816" 90 | // AMAP_API.getDrivingDirection(origin, destination, function(driving){ 91 | // console.debug("driving.info",driving.info) 92 | // }) 93 | function getDrivingDirection(origin, destination,callback){ 94 | var url = "http://restapi.amap.com/v3/direction/driving?key=" + amap_key 95 | url += "&origin=" + origin 96 | url += "+&destination=" +destination 97 | 98 | sendXMLHttpRequest(url,callback) 99 | } 100 | 101 | //输入提示 102 | function getInputtips(keywords, callback){ 103 | var url = "http://restapi.amap.com/v3/assistant/inputtips?key=" + amap_key 104 | url += "&keywords="+ keywords 105 | url += "&location=" +longitude +","+ latitude 106 | url += "&datatype=all" 107 | sendXMLHttpRequest(url,callback) 108 | } 109 | 110 | function getWeatherInfo(city, callback){ 111 | var url = "http://restapi.amap.com/v3/weather/weatherInfo?key=" + amap_key 112 | url += "&city=" + city 113 | sendXMLHttpRequest(url, callback) 114 | } 115 | 116 | -------------------------------------------------------------------------------- /fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SindenDev/QAMap/c9282374243c23fcdf62659343358993f4e457e8/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /fontawesome/FontAwesome.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import 'awesome.js' as Awesome 3 | 4 | Text { 5 | property string name:"version" 6 | text: Awesome.map[name] 7 | verticalAlignment: Text.AlignVCenter 8 | horizontalAlignment: Text.AlignHCenter 9 | font.family:"FontAwesome"// fontAwesome.name 10 | font.pixelSize: 24 11 | // Component.onCompleted: console.debug(Awesome.map['align_justify']) 12 | FontLoader { id: fontAwesome; source: "qrc:/fontawesome/FontAwesome.otf" } 13 | } 14 | -------------------------------------------------------------------------------- /fontawesome/awesome.js: -------------------------------------------------------------------------------- 1 | 2 | .pragma library 3 | 4 | var map = { 5 | 'version':'Font Awesome Version 4.7.0', 6 | '500px': '\uf26e', 7 | 'adjust': '\uf042', 8 | 'adn': '\uf170', 9 | 'align_center': '\uf037', 10 | 'align_justify': '\uf039', 11 | 'align_left': '\uf036', 12 | 'align_right': '\uf038', 13 | 'amazon': '\uf270', 14 | 'ambulance': '\uf0f9', 15 | 'anchor': '\uf13d', 16 | 'android': '\uf17b', 17 | 'angellist': '\uf209', 18 | 'angle_double_down': '\uf103', 19 | 'angle_double_left': '\uf100', 20 | 'angle_double_right': '\uf101', 21 | 'angle_double_up': '\uf102', 22 | 'angle_down': '\uf107', 23 | 'angle_left': '\uf104', 24 | 'angle_right': '\uf105', 25 | 'angle_up': '\uf106', 26 | 'apple': '\uf179', 27 | 'archive': '\uf187', 28 | 'area_chart': '\uf1fe', 29 | 'arrow_circle_down': '\uf0ab', 30 | 'arrow_circle_left': '\uf0a8', 31 | 'arrow_circle_o_down': '\uf01a', 32 | 'arrow_circle_o_left': '\uf190', 33 | 'arrow_circle_o_right': '\uf18e', 34 | 'arrow_circle_o_up': '\uf01b', 35 | 'arrow_circle_right': '\uf0a9', 36 | 'arrow_circle_up': '\uf0aa', 37 | 'arrow_down': '\uf063', 38 | 'arrow_left': '\uf060', 39 | 'arrow_right': '\uf061', 40 | 'arrow_up': '\uf062', 41 | 'arrows': '\uf047', 42 | 'arrows_alt': '\uf0b2', 43 | 'arrows_h': '\uf07e', 44 | 'arrows_v': '\uf07d', 45 | 'asterisk': '\uf069', 46 | 'at': '\uf1fa', 47 | 'automobile': '\uf1b9', 48 | 'backward': '\uf04a', 49 | 'balance_scale': '\uf24e', 50 | 'ban': '\uf05e', 51 | 'bank': '\uf19c', 52 | 'bar_chart': '\uf080', 53 | 'bar_chart_o': '\uf080', 54 | 'barcode': '\uf02a', 55 | 'bars': '\uf0c9', 56 | 'battery_0': '\uf244', 57 | 'battery_1': '\uf243', 58 | 'battery_2': '\uf242', 59 | 'battery_3': '\uf241', 60 | 'battery_4': '\uf240', 61 | 'battery_empty': '\uf244', 62 | 'battery_full': '\uf240', 63 | 'battery_half': '\uf242', 64 | 'battery_quarter': '\uf243', 65 | 'battery_three_quarters': '\uf241', 66 | 'bed': '\uf236', 67 | 'beer': '\uf0fc', 68 | 'behance': '\uf1b4', 69 | 'behance_square': '\uf1b5', 70 | 'bell': '\uf0f3', 71 | 'bell_o': '\uf0a2', 72 | 'bell_slash': '\uf1f6', 73 | 'bell_slash_o': '\uf1f7', 74 | 'bicycle': '\uf206', 75 | 'binoculars': '\uf1e5', 76 | 'birthday_cake': '\uf1fd', 77 | 'bitbucket': '\uf171', 78 | 'bitbucket_square': '\uf172', 79 | 'bitcoin': '\uf15a', 80 | 'black_tie': '\uf27e', 81 | 'bluetooth': '\uf293', 82 | 'bluetooth_b': '\uf294', 83 | 'bold': '\uf032', 84 | 'bolt': '\uf0e7', 85 | 'bomb': '\uf1e2', 86 | 'book': '\uf02d', 87 | 'bookmark': '\uf02e', 88 | 'bookmark_o': '\uf097', 89 | 'briefcase': '\uf0b1', 90 | 'btc': '\uf15a', 91 | 'bug': '\uf188', 92 | 'building': '\uf1ad', 93 | 'building_o': '\uf0f7', 94 | 'bullhorn': '\uf0a1', 95 | 'bullseye': '\uf140', 96 | 'bus': '\uf207', 97 | 'buysellads': '\uf20d', 98 | 'cab': '\uf1ba', 99 | 'calculator': '\uf1ec', 100 | 'calendar': '\uf073', 101 | 'calendar_check_o': '\uf274', 102 | 'calendar_minus_o': '\uf272', 103 | 'calendar_o': '\uf133', 104 | 'calendar_plus_o': '\uf271', 105 | 'calendar_times_o': '\uf273', 106 | 'camera': '\uf030', 107 | 'camera_retro': '\uf083', 108 | 'car': '\uf1b9', 109 | 'caret_down': '\uf0d7', 110 | 'caret_left': '\uf0d9', 111 | 'caret_right': '\uf0da', 112 | 'caret_square_o_down': '\uf150', 113 | 'caret_square_o_left': '\uf191', 114 | 'caret_square_o_right': '\uf152', 115 | 'caret_square_o_up': '\uf151', 116 | 'caret_up': '\uf0d8', 117 | 'cart_arrow_down': '\uf218', 118 | 'cart_plus': '\uf217', 119 | 'cc': '\uf20a', 120 | 'cc_amex': '\uf1f3', 121 | 'cc_diners_club': '\uf24c', 122 | 'cc_discover': '\uf1f2', 123 | 'cc_jcb': '\uf24b', 124 | 'cc_mastercard': '\uf1f1', 125 | 'cc_paypal': '\uf1f4', 126 | 'cc_stripe': '\uf1f5', 127 | 'cc_visa': '\uf1f0', 128 | 'certificate': '\uf0a3', 129 | 'chain': '\uf0c1', 130 | 'chain_broken': '\uf127', 131 | 'check': '\uf00c', 132 | 'check_circle': '\uf058', 133 | 'check_circle_o': '\uf05d', 134 | 'check_square': '\uf14a', 135 | 'check_square_o': '\uf046', 136 | 'chevron_circle_down': '\uf13a', 137 | 'chevron_circle_left': '\uf137', 138 | 'chevron_circle_right': '\uf138', 139 | 'chevron_circle_up': '\uf139', 140 | 'chevron_down': '\uf078', 141 | 'chevron_left': '\uf053', 142 | 'chevron_right': '\uf054', 143 | 'chevron_up': '\uf077', 144 | 'child': '\uf1ae', 145 | 'chrome': '\uf268', 146 | 'circle': '\uf111', 147 | 'circle_o': '\uf10c', 148 | 'circle_o_notch': '\uf1ce', 149 | 'circle_thin': '\uf1db', 150 | 'clipboard': '\uf0ea', 151 | 'clock_o': '\uf017', 152 | 'clone': '\uf24d', 153 | 'close': '\uf00d', 154 | 'cloud': '\uf0c2', 155 | 'cloud_download': '\uf0ed', 156 | 'cloud_upload': '\uf0ee', 157 | 'cny': '\uf157', 158 | 'code': '\uf121', 159 | 'code_fork': '\uf126', 160 | 'codepen': '\uf1cb', 161 | 'codiepie': '\uf284', 162 | 'coffee': '\uf0f4', 163 | 'cog': '\uf013', 164 | 'cogs': '\uf085', 165 | 'columns': '\uf0db', 166 | 'comment': '\uf075', 167 | 'comment_o': '\uf0e5', 168 | 'commenting': '\uf27a', 169 | 'commenting_o': '\uf27b', 170 | 'comments': '\uf086', 171 | 'comments_o': '\uf0e6', 172 | 'compass': '\uf14e', 173 | 'compress': '\uf066', 174 | 'connectdevelop': '\uf20e', 175 | 'contao': '\uf26d', 176 | 'copy': '\uf0c5', 177 | 'copyright': '\uf1f9', 178 | 'creative_commons': '\uf25e', 179 | 'credit_card': '\uf09d', 180 | 'credit_card_alt': '\uf283', 181 | 'crop': '\uf125', 182 | 'crosshairs': '\uf05b', 183 | 'css3': '\uf13c', 184 | 'cube': '\uf1b2', 185 | 'cubes': '\uf1b3', 186 | 'cut': '\uf0c4', 187 | 'cutlery': '\uf0f5', 188 | 'dashboard': '\uf0e4', 189 | 'dashcube': '\uf210', 190 | 'database': '\uf1c0', 191 | 'dedent': '\uf03b', 192 | 'delicious': '\uf1a5', 193 | 'desktop': '\uf108', 194 | 'deviantart': '\uf1bd', 195 | 'diamond': '\uf219', 196 | 'digg': '\uf1a6', 197 | 'dollar': '\uf155', 198 | 'dot_circle_o': '\uf192', 199 | 'download': '\uf019', 200 | 'dribbble': '\uf17d', 201 | 'dropbox': '\uf16b', 202 | 'drupal': '\uf1a9', 203 | 'edge': '\uf282', 204 | 'edit': '\uf044', 205 | 'eject': '\uf052', 206 | 'ellipsis_h': '\uf141', 207 | 'ellipsis_v': '\uf142', 208 | 'empire': '\uf1d1', 209 | 'envelope': '\uf0e0', 210 | 'envelope_o': '\uf003', 211 | 'envelope_square': '\uf199', 212 | 'eraser': '\uf12d', 213 | 'eur': '\uf153', 214 | 'euro': '\uf153', 215 | 'exchange': '\uf0ec', 216 | 'exclamation': '\uf12a', 217 | 'exclamation_circle': '\uf06a', 218 | 'exclamation_triangle': '\uf071', 219 | 'expand': '\uf065', 220 | 'expeditedssl': '\uf23e', 221 | 'external_link': '\uf08e', 222 | 'external_link_square': '\uf14c', 223 | 'eye': '\uf06e', 224 | 'eye_slash': '\uf070', 225 | 'eyedropper': '\uf1fb', 226 | 'facebook': '\uf09a', 227 | 'facebook_f': '\uf09a', 228 | 'facebook_official': '\uf230', 229 | 'facebook_square': '\uf082', 230 | 'fast_backward': '\uf049', 231 | 'fast_forward': '\uf050', 232 | 'fax': '\uf1ac', 233 | 'feed': '\uf09e', 234 | 'female': '\uf182', 235 | 'fighter_jet': '\uf0fb', 236 | 'file': '\uf15b', 237 | 'file_archive_o': '\uf1c6', 238 | 'file_audio_o': '\uf1c7', 239 | 'file_code_o': '\uf1c9', 240 | 'file_excel_o': '\uf1c3', 241 | 'file_image_o': '\uf1c5', 242 | 'file_movie_o': '\uf1c8', 243 | 'file_o': '\uf016', 244 | 'file_pdf_o': '\uf1c1', 245 | 'file_photo_o': '\uf1c5', 246 | 'file_picture_o': '\uf1c5', 247 | 'file_powerpoint_o': '\uf1c4', 248 | 'file_sound_o': '\uf1c7', 249 | 'file_text': '\uf15c', 250 | 'file_text_o': '\uf0f6', 251 | 'file_video_o': '\uf1c8', 252 | 'file_word_o': '\uf1c2', 253 | 'file_zip_o': '\uf1c6', 254 | 'files_o': '\uf0c5', 255 | 'film': '\uf008', 256 | 'filter': '\uf0b0', 257 | 'fire': '\uf06d', 258 | 'fire_extinguisher': '\uf134', 259 | 'firefox': '\uf269', 260 | 'flag': '\uf024', 261 | 'flag_checkered': '\uf11e', 262 | 'flag_o': '\uf11d', 263 | 'flash': '\uf0e7', 264 | 'flask': '\uf0c3', 265 | 'flickr': '\uf16e', 266 | 'floppy_o': '\uf0c7', 267 | 'folder': '\uf07b', 268 | 'folder_o': '\uf114', 269 | 'folder_open': '\uf07c', 270 | 'folder_open_o': '\uf115', 271 | 'font': '\uf031', 272 | 'fonticons': '\uf280', 273 | 'fort_awesome': '\uf286', 274 | 'forumbee': '\uf211', 275 | 'forward': '\uf04e', 276 | 'foursquare': '\uf180', 277 | 'frown_o': '\uf119', 278 | 'futbol_o': '\uf1e3', 279 | 'gamepad': '\uf11b', 280 | 'gavel': '\uf0e3', 281 | 'gbp': '\uf154', 282 | 'ge': '\uf1d1', 283 | 'gear': '\uf013', 284 | 'gears': '\uf085', 285 | 'get_pocket': '\uf265', 286 | 'gg': '\uf260', 287 | 'gg_circle': '\uf261', 288 | 'gift': '\uf06b', 289 | 'git': '\uf1d3', 290 | 'git_square': '\uf1d2', 291 | 'github': '\uf09b', 292 | 'github_alt': '\uf113', 293 | 'github_square': '\uf092', 294 | 'gittip': '\uf184', 295 | 'glass': '\uf000', 296 | 'globe': '\uf0ac', 297 | 'google': '\uf1a0', 298 | 'google_plus': '\uf0d5', 299 | 'google_plus_square': '\uf0d4', 300 | 'google_wallet': '\uf1ee', 301 | 'graduation_cap': '\uf19d', 302 | 'gratipay': '\uf184', 303 | 'group': '\uf0c0', 304 | 'h_square': '\uf0fd', 305 | 'hacker_news': '\uf1d4', 306 | 'hand_grab_o': '\uf255', 307 | 'hand_lizard_o': '\uf258', 308 | 'hand_o_down': '\uf0a7', 309 | 'hand_o_left': '\uf0a5', 310 | 'hand_o_right': '\uf0a4', 311 | 'hand_o_up': '\uf0a6', 312 | 'hand_paper_o': '\uf256', 313 | 'hand_peace_o': '\uf25b', 314 | 'hand_pointer_o': '\uf25a', 315 | 'hand_rock_o': '\uf255', 316 | 'hand_scissors_o': '\uf257', 317 | 'hand_spock_o': '\uf259', 318 | 'hand_stop_o': '\uf256', 319 | 'hashtag': '\uf292', 320 | 'hdd_o': '\uf0a0', 321 | 'header': '\uf1dc', 322 | 'headphones': '\uf025', 323 | 'heart': '\uf004', 324 | 'heart_o': '\uf08a', 325 | 'heartbeat': '\uf21e', 326 | 'history': '\uf1da', 327 | 'home': '\uf015', 328 | 'hospital_o': '\uf0f8', 329 | 'hotel': '\uf236', 330 | 'hourglass': '\uf254', 331 | 'hourglass_1': '\uf251', 332 | 'hourglass_2': '\uf252', 333 | 'hourglass_3': '\uf253', 334 | 'hourglass_end': '\uf253', 335 | 'hourglass_half': '\uf252', 336 | 'hourglass_o': '\uf250', 337 | 'hourglass_start': '\uf251', 338 | 'houzz': '\uf27c', 339 | 'html5': '\uf13b', 340 | 'i_cursor': '\uf246', 341 | 'ils': '\uf20b', 342 | 'image': '\uf03e', 343 | 'inbox': '\uf01c', 344 | 'indent': '\uf03c', 345 | 'industry': '\uf275', 346 | 'info': '\uf129', 347 | 'info_circle': '\uf05a', 348 | 'inr': '\uf156', 349 | 'instagram': '\uf16d', 350 | 'institution': '\uf19c', 351 | 'internet_explorer': '\uf26b', 352 | 'ioxhost': '\uf208', 353 | 'italic': '\uf033', 354 | 'joomla': '\uf1aa', 355 | 'jpy': '\uf157', 356 | 'jsfiddle': '\uf1cc', 357 | 'key': '\uf084', 358 | 'keyboard_o': '\uf11c', 359 | 'krw': '\uf159', 360 | 'language': '\uf1ab', 361 | 'laptop': '\uf109', 362 | 'lastfm': '\uf202', 363 | 'lastfm_square': '\uf203', 364 | 'leaf': '\uf06c', 365 | 'leanpub': '\uf212', 366 | 'legal': '\uf0e3', 367 | 'lemon_o': '\uf094', 368 | 'level_down': '\uf149', 369 | 'level_up': '\uf148', 370 | 'life_bouy': '\uf1cd', 371 | 'life_buoy': '\uf1cd', 372 | 'life_ring': '\uf1cd', 373 | 'life_saver': '\uf1cd', 374 | 'lightbulb_o': '\uf0eb', 375 | 'line_chart': '\uf201', 376 | 'link': '\uf0c1', 377 | 'linkedin': '\uf0e1', 378 | 'linkedin_square': '\uf08c', 379 | 'linux': '\uf17c', 380 | 'list': '\uf03a', 381 | 'list_alt': '\uf022', 382 | 'list_ol': '\uf0cb', 383 | 'list_ul': '\uf0ca', 384 | 'location_arrow': '\uf124', 385 | 'lock': '\uf023', 386 | 'long_arrow_down': '\uf175', 387 | 'long_arrow_left': '\uf177', 388 | 'long_arrow_right': '\uf178', 389 | 'long_arrow_up': '\uf176', 390 | 'magic': '\uf0d0', 391 | 'magnet': '\uf076', 392 | 'mail_forward': '\uf064', 393 | 'mail_reply': '\uf112', 394 | 'mail_reply_all': '\uf122', 395 | 'male': '\uf183', 396 | 'map': '\uf279', 397 | 'map_marker': '\uf041', 398 | 'map_o': '\uf278', 399 | 'map_pin': '\uf276', 400 | 'map_signs': '\uf277', 401 | 'maxcdn': '\uf136', 402 | 'meanpath': '\uf20c', 403 | 'medium': '\uf23a', 404 | 'medkit': '\uf0fa', 405 | 'meh_o': '\uf11a', 406 | 'microphone': '\uf130', 407 | 'microphone_slash': '\uf131', 408 | 'minus': '\uf068', 409 | 'minus_circle': '\uf056', 410 | 'minus_square': '\uf146', 411 | 'minus_square_o': '\uf147', 412 | 'mixcloud': '\uf289', 413 | 'mobile': '\uf10b', 414 | 'mobile_phone': '\uf10b', 415 | 'modx': '\uf285', 416 | 'money': '\uf0d6', 417 | 'moon_o': '\uf186', 418 | 'mortar_board': '\uf19d', 419 | 'motorcycle': '\uf21c', 420 | 'mouse_pointer': '\uf245', 421 | 'music': '\uf001', 422 | 'navicon': '\uf0c9', 423 | 'newspaper_o': '\uf1ea', 424 | 'object_group': '\uf247', 425 | 'object_ungroup': '\uf248', 426 | 'odnoklassniki': '\uf263', 427 | 'odnoklassniki_square': '\uf264', 428 | 'opencart': '\uf23d', 429 | 'openid': '\uf19b', 430 | 'opera': '\uf26a', 431 | 'optin_monster': '\uf23c', 432 | 'outdent': '\uf03b', 433 | 'pagelines': '\uf18c', 434 | 'paint_brush': '\uf1fc', 435 | 'paper_plane': '\uf1d8', 436 | 'paper_plane_o': '\uf1d9', 437 | 'paperclip': '\uf0c6', 438 | 'paragraph': '\uf1dd', 439 | 'paste': '\uf0ea', 440 | 'pause': '\uf04c', 441 | 'pause_circle': '\uf28b', 442 | 'pause_circle_o': '\uf28c', 443 | 'paw': '\uf1b0', 444 | 'paypal': '\uf1ed', 445 | 'pencil': '\uf040', 446 | 'pencil_square': '\uf14b', 447 | 'pencil_square_o': '\uf044', 448 | 'percent': '\uf295', 449 | 'phone': '\uf095', 450 | 'phone_square': '\uf098', 451 | 'photo': '\uf03e', 452 | 'picture_o': '\uf03e', 453 | 'pie_chart': '\uf200', 454 | 'pied_piper': '\uf1a7', 455 | 'pied_piper_alt': '\uf1a8', 456 | 'pinterest': '\uf0d2', 457 | 'pinterest_p': '\uf231', 458 | 'pinterest_square': '\uf0d3', 459 | 'plane': '\uf072', 460 | 'play': '\uf04b', 461 | 'play_circle': '\uf144', 462 | 'play_circle_o': '\uf01d', 463 | 'plug': '\uf1e6', 464 | 'plus': '\uf067', 465 | 'plus_circle': '\uf055', 466 | 'plus_square': '\uf0fe', 467 | 'plus_square_o': '\uf196', 468 | 'power_off': '\uf011', 469 | 'print': '\uf02f', 470 | 'product_hunt': '\uf288', 471 | 'puzzle_piece': '\uf12e', 472 | 'qq': '\uf1d6', 473 | 'qrcode': '\uf029', 474 | 'question': '\uf128', 475 | 'question_circle': '\uf059', 476 | 'quote_left': '\uf10d', 477 | 'quote_right': '\uf10e', 478 | 'ra': '\uf1d0', 479 | 'random': '\uf074', 480 | 'rebel': '\uf1d0', 481 | 'recycle': '\uf1b8', 482 | 'reddit': '\uf1a1', 483 | 'reddit_alien': '\uf281', 484 | 'reddit_square': '\uf1a2', 485 | 'refresh': '\uf021', 486 | 'registered': '\uf25d', 487 | 'remove': '\uf00d', 488 | 'renren': '\uf18b', 489 | 'reorder': '\uf0c9', 490 | 'repeat': '\uf01e', 491 | 'reply': '\uf112', 492 | 'reply_all': '\uf122', 493 | 'retweet': '\uf079', 494 | 'rmb': '\uf157', 495 | 'road': '\uf018', 496 | 'rocket': '\uf135', 497 | 'rotate_left': '\uf0e2', 498 | 'rotate_right': '\uf01e', 499 | 'rouble': '\uf158', 500 | 'rss': '\uf09e', 501 | 'rss_square': '\uf143', 502 | 'rub': '\uf158', 503 | 'ruble': '\uf158', 504 | 'rupee': '\uf156', 505 | 'safari': '\uf267', 506 | 'save': '\uf0c7', 507 | 'scissors': '\uf0c4', 508 | 'scribd': '\uf28a', 509 | 'search': '\uf002', 510 | 'search_minus': '\uf010', 511 | 'search_plus': '\uf00e', 512 | 'sellsy': '\uf213', 513 | 'send': '\uf1d8', 514 | 'send_o': '\uf1d9', 515 | 'server': '\uf233', 516 | 'share': '\uf064', 517 | 'share_alt': '\uf1e0', 518 | 'share_alt_square': '\uf1e1', 519 | 'share_square': '\uf14d', 520 | 'share_square_o': '\uf045', 521 | 'shekel': '\uf20b', 522 | 'sheqel': '\uf20b', 523 | 'shield': '\uf132', 524 | 'ship': '\uf21a', 525 | 'shirtsinbulk': '\uf214', 526 | 'shopping_bag': '\uf290', 527 | 'shopping_basket': '\uf291', 528 | 'shopping_cart': '\uf07a', 529 | 'sign_in': '\uf090', 530 | 'sign_out': '\uf08b', 531 | 'signal': '\uf012', 532 | 'simplybuilt': '\uf215', 533 | 'sitemap': '\uf0e8', 534 | 'skyatlas': '\uf216', 535 | 'skype': '\uf17e', 536 | 'slack': '\uf198', 537 | 'sliders': '\uf1de', 538 | 'slideshare': '\uf1e7', 539 | 'smile_o': '\uf118', 540 | 'soccer_ball_o': '\uf1e3', 541 | 'sort': '\uf0dc', 542 | 'sort_alpha_asc': '\uf15d', 543 | 'sort_alpha_desc': '\uf15e', 544 | 'sort_amount_asc': '\uf160', 545 | 'sort_amount_desc': '\uf161', 546 | 'sort_asc': '\uf0de', 547 | 'sort_desc': '\uf0dd', 548 | 'sort_down': '\uf0dd', 549 | 'sort_numeric_asc': '\uf162', 550 | 'sort_numeric_desc': '\uf163', 551 | 'sort_up': '\uf0de', 552 | 'soundcloud': '\uf1be', 553 | 'space_shuttle': '\uf197', 554 | 'spinner': '\uf110', 555 | 'spoon': '\uf1b1', 556 | 'spotify': '\uf1bc', 557 | 'square': '\uf0c8', 558 | 'square_o': '\uf096', 559 | 'stack_exchange': '\uf18d', 560 | 'stack_overflow': '\uf16c', 561 | 'star': '\uf005', 562 | 'star_half': '\uf089', 563 | 'star_half_empty': '\uf123', 564 | 'star_half_full': '\uf123', 565 | 'star_half_o': '\uf123', 566 | 'star_o': '\uf006', 567 | 'steam': '\uf1b6', 568 | 'steam_square': '\uf1b7', 569 | 'step_backward': '\uf048', 570 | 'step_forward': '\uf051', 571 | 'stethoscope': '\uf0f1', 572 | 'sticky_note': '\uf249', 573 | 'sticky_note_o': '\uf24a', 574 | 'stop': '\uf04d', 575 | 'stop_circle': '\uf28d', 576 | 'stop_circle_o': '\uf28e', 577 | 'street_view': '\uf21d', 578 | 'strikethrough': '\uf0cc', 579 | 'stumbleupon': '\uf1a4', 580 | 'stumbleupon_circle': '\uf1a3', 581 | 'subscript': '\uf12c', 582 | 'subway': '\uf239', 583 | 'suitcase': '\uf0f2', 584 | 'sun_o': '\uf185', 585 | 'superscript': '\uf12b', 586 | 'support': '\uf1cd', 587 | 'table': '\uf0ce', 588 | 'tablet': '\uf10a', 589 | 'tachometer': '\uf0e4', 590 | 'tag': '\uf02b', 591 | 'tags': '\uf02c', 592 | 'tasks': '\uf0ae', 593 | 'taxi': '\uf1ba', 594 | 'television': '\uf26c', 595 | 'tencent_weibo': '\uf1d5', 596 | 'terminal': '\uf120', 597 | 'text_height': '\uf034', 598 | 'text_width': '\uf035', 599 | 'th': '\uf00a', 600 | 'th_large': '\uf009', 601 | 'th_list': '\uf00b', 602 | 'thumb_tack': '\uf08d', 603 | 'thumbs_down': '\uf165', 604 | 'thumbs_o_down': '\uf088', 605 | 'thumbs_o_up': '\uf087', 606 | 'thumbs_up': '\uf164', 607 | 'ticket': '\uf145', 608 | 'times': '\uf00d', 609 | 'times_circle': '\uf057', 610 | 'times_circle_o': '\uf05c', 611 | 'tint': '\uf043', 612 | 'toggle_down': '\uf150', 613 | 'toggle_left': '\uf191', 614 | 'toggle_off': '\uf204', 615 | 'toggle_on': '\uf205', 616 | 'toggle_right': '\uf152', 617 | 'toggle_up': '\uf151', 618 | 'trademark': '\uf25c', 619 | 'train': '\uf238', 620 | 'trash': '\uf1f8', 621 | 'trash_o': '\uf014', 622 | 'tree': '\uf1bb', 623 | 'trello': '\uf181', 624 | 'tripadvisor': '\uf262', 625 | 'trophy': '\uf091', 626 | 'truck': '\uf0d1', 627 | 'try': '\uf195', 628 | 'tty': '\uf1e4', 629 | 'tumblr': '\uf173', 630 | 'tumblr_square': '\uf174', 631 | 'turkish_lira': '\uf195', 632 | 'tv': '\uf26c', 633 | 'twitch': '\uf1e8', 634 | 'twitter': '\uf099', 635 | 'twitter_square': '\uf081', 636 | 'umbrella': '\uf0e9', 637 | 'underline': '\uf0cd', 638 | 'undo': '\uf0e2', 639 | 'university': '\uf19c', 640 | 'unlink': '\uf127', 641 | 'unlock': '\uf09c', 642 | 'unlock_alt': '\uf13e', 643 | 'unsorted': '\uf0dc', 644 | 'upload': '\uf093', 645 | 'usb': '\uf287', 646 | 'usd': '\uf155', 647 | 'user': '\uf007', 648 | 'user_md': '\uf0f0', 649 | 'user_plus': '\uf234', 650 | 'user_secret': '\uf21b', 651 | 'user_times': '\uf235', 652 | 'users': '\uf0c0', 653 | 'viacoin': '\uf237', 654 | 'video_camera': '\uf03d', 655 | 'vimeo': '\uf27d', 656 | 'vimeo_square': '\uf194', 657 | 'vine': '\uf1ca', 658 | 'vk': '\uf189', 659 | 'volume_down': '\uf027', 660 | 'volume_off': '\uf026', 661 | 'volume_up': '\uf028', 662 | 'warning': '\uf071', 663 | 'wechat': '\uf1d7', 664 | 'weibo': '\uf18a', 665 | 'weixin': '\uf1d7', 666 | 'whatsapp': '\uf232', 667 | 'wheelchair': '\uf193', 668 | 'wifi': '\uf1eb', 669 | 'wikipedia_w': '\uf266', 670 | 'windows': '\uf17a', 671 | 'won': '\uf159', 672 | 'wordpress': '\uf19a', 673 | 'wrench': '\uf0ad', 674 | 'xing': '\uf168', 675 | 'xing_square': '\uf169', 676 | 'y_combinator': '\uf23b', 677 | 'y_combinator_square': '\uf1d4', 678 | 'yahoo': '\uf19e', 679 | 'yc': '\uf23b', 680 | 'yc_square': '\uf1d4', 681 | 'yelp': '\uf1e9', 682 | 'yen': '\uf157', 683 | 'youtube': '\uf167', 684 | 'youtube_play': '\uf16a', 685 | 'youtube_square': '\uf166', 686 | 687 | }; 688 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | 9 | qDebug() << QDateTime::currentDateTimeUtc().toSecsSinceEpoch()<<"\n" << QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(); 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.8 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | AMap{ 11 | anchors.fill: parent 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | AMap.qml 5 | amap.js 6 | fontawesome/awesome.js 7 | fontawesome/FontAwesome.otf 8 | fontawesome/FontAwesome.qml 9 | MapSearchItem.qml 10 | transform.js 11 | 12 | 13 | -------------------------------------------------------------------------------- /transform.js: -------------------------------------------------------------------------------- 1 | //调整位置偏移 2 | var earthR = 6378137.0; 3 | var transformMapName = "amap"// "googlemaps" 4 | function outOfChina(lat, lng) { 5 | if ((lng < 72.004) || (lng > 137.8347)) { 6 | return true; 7 | } 8 | if ((lat < 0.8293) || (lat > 55.8271)) { 9 | return true; 10 | } 11 | return false; 12 | } 13 | 14 | function transform(x, y) { 15 | var xy = x * y; 16 | var absX = Math.sqrt(Math.abs(x)); 17 | var xPi = x * Math.PI; 18 | var yPi = y * Math.PI; 19 | var d = 20.0*Math.sin(6.0*xPi) + 20.0*Math.sin(2.0*xPi); 20 | 21 | var lat = d; 22 | var lng = d; 23 | 24 | lat += 20.0*Math.sin(yPi) + 40.0*Math.sin(yPi/3.0); 25 | lng += 20.0*Math.sin(xPi) + 40.0*Math.sin(xPi/3.0); 26 | 27 | lat += 160.0*Math.sin(yPi/12.0) + 320*Math.sin(yPi/30.0); 28 | lng += 150.0*Math.sin(xPi/12.0) + 300.0*Math.sin(xPi/30.0); 29 | 30 | lat *= 2.0 / 3.0; 31 | lng *= 2.0 / 3.0; 32 | 33 | lat += -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*xy + 0.2*absX; 34 | lng += 300.0 + x + 2.0*y + 0.1*x*x + 0.1*xy + 0.1*absX; 35 | 36 | return {lat: lat, lng: lng} 37 | } 38 | 39 | function delta(lat, lng) { 40 | var ee = 0.00669342162296594323; 41 | var d = transform(lng-105.0, lat-35.0); 42 | var radLat = lat / 180.0 * Math.PI; 43 | var magic = Math.sin(radLat); 44 | magic = 1 - ee*magic*magic; 45 | var sqrtMagic = Math.sqrt(magic); 46 | d.lat = (d.lat * 180.0) / ((earthR * (1 - ee)) / (magic * sqrtMagic) * Math.PI); 47 | d.lng = (d.lng * 180.0) / (earthR / sqrtMagic * Math.cos(radLat) * Math.PI); 48 | return d; 49 | } 50 | 51 | function wgs2gcj(wgsLat, wgsLng) { 52 | if (outOfChina(wgsLat, wgsLng)) { 53 | return {lat: wgsLat, lng: wgsLng}; 54 | } 55 | var d = delta(wgsLat, wgsLng); 56 | return {lat: wgsLat + d.lat, lon: wgsLng + d.lng}; 57 | } 58 | //exports.wgs2gcj = wgs2gcj; 59 | 60 | function gcj2wgs(gcjLat, gcjLng) { 61 | if (outOfChina(gcjLat, gcjLng)) { 62 | return {lat: gcjLat, lng: gcjLng}; 63 | } 64 | var d = delta(gcjLat, gcjLng); 65 | return {lat: gcjLat - d.lat, lng: gcjLng - d.lng}; 66 | } 67 | //exports.gcj2wgs = gcj2wgs; 68 | 69 | function gcj2wgs_exact(gcjLat, gcjLng) { 70 | // newCoord = oldCoord = gcjCoord 71 | var newLat = gcjLat, newLng = gcjLng; 72 | var oldLat = newLat, oldLng = newLng; 73 | var threshold = 1e-6; // ~0.55 m equator & latitude 74 | 75 | for (var i = 0; i < 30; i++) { 76 | // oldCoord = newCoord 77 | oldLat = newLat; 78 | oldLng = newLng; 79 | // newCoord = gcjCoord - wgs_to_gcj_delta(newCoord) 80 | var tmp = wgs2gcj(newLat, newLng); 81 | // approx difference using gcj-space difference 82 | newLat -= gcjLat - tmp.lat; 83 | newLng -= gcjLng - tmp.lng; 84 | // diffchk 85 | if (Math.max(Math.abs(oldLat - newLat), Math.abs(oldLng - newLng)) < threshold) { 86 | break; 87 | } 88 | } 89 | return {lat: newLat, lng: newLng}; 90 | } 91 | //exports.gcj2wgs_exact = gcj2wgs_exact; 92 | 93 | function distance(latA, lngA, latB, lngB) { 94 | var pi180 = Math.PI / 180; 95 | var arcLatA = latA * pi180; 96 | var arcLatB = latB * pi180; 97 | var x = Math.cos(arcLatA) * Math.cos(arcLatB) * Math.cos((lngA-lngB)*pi180); 98 | var y = Math.sin(arcLatA) * Math.sin(arcLatB); 99 | var s = x + y; 100 | if (s > 1) { 101 | s = 1; 102 | } 103 | if (s < -1) { 104 | s = -1; 105 | } 106 | var alpha = Math.acos(s); 107 | var distance = alpha * earthR; 108 | return distance; 109 | } 110 | //exports.distance = distance; 111 | 112 | function gcj2bd(gcjLat, gcjLng) { 113 | if (outOfChina(gcjLat, gcjLng)) { 114 | return {lat: gcjLat, lng: gcjLng}; 115 | } 116 | 117 | var x = gcjLng, y = gcjLat; 118 | var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * Math.PI); 119 | var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * Math.PI); 120 | var bdLng = z * Math.cos(theta) + 0.0065; 121 | var bdLat = z * Math.sin(theta) + 0.006; 122 | return {lat: bdLat, lng: bdLng}; 123 | } 124 | //exports.gcj2bd = gcj2bd; 125 | 126 | function bd2gcj(bdLat, bdLng) { 127 | if (outOfChina(bdLat, bdLng)) { 128 | return {lat: bdLat, lng: bdLng}; 129 | } 130 | 131 | var x = bdLng - 0.0065, y = bdLat - 0.006; 132 | var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * Math.PI); 133 | var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * Math.PI); 134 | var gcjLng = z * Math.cos(theta); 135 | var gcjLat = z * Math.sin(theta); 136 | return {lat: gcjLat, lng: gcjLng}; 137 | } 138 | //exports.bd2gcj = bd2gcj; 139 | 140 | function wgs2bd(wgsLat, wgsLng) { 141 | var gcj = wgs2gcj(wgsLat, wgsLng); 142 | return gcj2bd(gcj.lat, gcj.lng); 143 | } 144 | //exports.wgs2bd = wgs2bd; 145 | 146 | function bd2wgs(bdLat, bdLng) { 147 | var gcj = bd2gcj(bdLat, bdLng); 148 | return gcj2wgs(gcj.lat, gcj.lng); 149 | } 150 | //exports.bd2wgs = bd2wgs; 151 | --------------------------------------------------------------------------------