{"rsdb":{"rid":"394988","subhead":"","postdate":"0","aid":"272416","fid":"100","uid":"1","topic":"1","content":"
\n

\u8fd9\u91cc\u7ed9\u5927\u5bb6\u5206\u4eab\u6211\u5728\u7f51\u4e0a\u603b\u7ed3\u51fa\u6765\u7684\u4e00\u4e9b\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9<\/span><\/h3> \n

<\/a><\/span><\/p> \n

1.uni.getLocation \u83b7\u53d6\u5f53\u524d\u7ecf\u7ef4\u5ea6<\/span><\/h2> \n

 \u5148\u4e0a\u4ee3\u7801<\/h3> \n
\n
  let that = this\n                \/\/ \u83b7\u53d6\u7528\u6237\u662f\u5426\u5f00\u542f \u6388\u6743\u83b7\u53d6\u5f53\u524d\u7684\u5730\u7406\u4f4d\u7f6e\u3001\u901f\u5ea6\u7684\u6743\u9650\u3002\n                uni.getSetting({\n                    success (res) {\n                        console.log(res)\n                        \/\/ \u5982\u679c\u6ca1\u6709\u6388\u6743\n                        if (!res.authSetting['scope.userLocation']) {\n                            \/\/ \u5219\u62c9\u8d77\u6388\u6743\u7a97\u53e3\n                            uni.authorize({\n                                scope: 'scope.userLocation',\n                                success () {\n                                \/\/\u70b9\u51fb\u5141\u8bb8\u540e--\u5c31\u4e00\u76f4\u4f1a\u8fdb\u5165\u6210\u529f\u6388\u6743\u7684\u56de\u8c03 \u5c31\u53ef\u4ee5\u4f7f\u7528\u83b7\u53d6\u7684\u65b9\u6cd5\u4e86\n                                    uni.getLocation({\n                                        type: 'wgs84',\n                                        success: function (res) {\n                                            that.longitude = res.longitude\n                                            that.latitude = res.latitude\n                                            let jinweidu = {\n                                                longitude: res.longitude,\n                                                latitude: res.latitude,\n                                            }\n                                            uni.setStorageSync('jinweidu', jinweidu);\n                                            console.log(res)\n                                            console.log('\u5f53\u524d\u4f4d\u7f6e\u7684\u7ecf\u5ea6\uff1a' + res.longitude)\n                                            console.log('\u5f53\u524d\u4f4d\u7f6e\u7684\u7eac\u5ea6\uff1a' + res.latitude)\n                                            that.getlist()\n                                        }, fail (error) {\n                                            uni.showToast({\n                                                title: '\u83b7\u53d6\u5730\u5740\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u624b\u673a\u662f\u5426\u6253\u5f00\u5b9a\u4f4d\u529f\u80fd\uff0c\u672a\u6253\u5f00\u5c06\u5bfc\u81f4\u90e8\u5206\u529f\u80fd\u4e0d\u53ef\u7528',\n                                                icon:'none'\n                                            });\n                                        }\n                                    })\n                                },\n                                fail (error) {\n                                    \/\/\u70b9\u51fb\u4e86\u62d2\u7edd\u6388\u6743\u540e--\u5c31\u4e00\u76f4\u4f1a\u8fdb\u5165\u5931\u8d25\u56de\u8c03\u51fd\u6570--\u6b64\u65f6\u5c31\u53ef\u4ee5\u5728\u8fd9\u91cc\u91cd\u65b0\u62c9\u8d77\u6388\u6743\u7a97\u53e3\n                                    console.log('\u62d2\u7edd\u6388\u6743', error)\n                                    uni.showModal({\n                                        title: '\u63d0\u793a',\n                                        content: '\u82e5\u70b9\u51fb\u4e0d\u6388\u6743\uff0c\u5c06\u65e0\u6cd5\u4f7f\u7528\u4f4d\u7f6e\u529f\u80fd',\n                                        showCancel: false,\n                                        \/\/ cancelText: '\u4e0d\u6388\u6743',\n                                        \/\/ cancelColor: '#999',\n                                        confirmText: '\u6388\u6743',\n                                        confirmColor: '#f94218',\n                                        success (res) {\n                                            console.log(res)\n                                            if (res.confirm) {\n                                                \/\/ \u9009\u62e9\u5f39\u6846\u5185\u6388\u6743\n                                                uni.openSetting({\n                                                    success (res) {\n                                                        console.log(res.authSetting)\n                                                    }\n                                                })\n                                            } else if (res.cancel) {\n                                                \/\/ \u9009\u62e9\u5f39\u6846\u5185 \u4e0d\u6388\u6743\n                                                console.log('\u7528\u6237\u70b9\u51fb\u4e0d\u6388\u6743')\n                                            }\n                                        }\n                                    })\n                                }\n                            })\n                        } else {\n                            \/\/ \u6709\u6743\u9650\u5219\u76f4\u63a5\u83b7\u53d6\n                            uni.getLocation({\n                                type: 'wgs84',\n                                success: function (res) {\n                                    that.longitude = res.longitude\n                                    that.latitude = res.latitude\n                                    let jinweidu = {\n                                        longitude: res.longitude,\n                                        latitude: res.latitude,\n                                    }\n                                    uni.setStorageSync('jinweidu', jinweidu);\n                                    console.log(res)\n                                    console.log('\u5f53\u524d\u4f4d\u7f6e\u7684\u7ecf\u5ea61\uff1a' + res.longitude)\n                                    console.log('\u5f53\u524d\u4f4d\u7f6e\u7684\u7eac\u5ea61\uff1a' + res.latitude)\n                                    that.getlist()\n                                }, fail (error) {\n                                    uni.showToast({\n                                        title: '\u83b7\u53d6\u5730\u5740\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u624b\u673a\u662f\u5426\u6253\u5f00\u5b9a\u4f4d\u529f\u80fd\uff0c\u672a\u6253\u5f00\u5c06\u5bfc\u81f4\u90e8\u5206\u529f\u80fd\u4e0d\u53ef\u7528',\n                                        icon:'none'\n                                    });\n                                    console.log('\u5931\u8d25', error)\n                                }\n                            })\n                        }\n                    }\n                })\n            \n            }\n<\/pre> \n <\/div> \n 

\u5c06\u6b64\u65b9\u6cd5\u653e\u5230onLoad\u751f\u547d\u5468\u671f\u5185\uff0c\u7b2c\u4e00\u6b21\u8fdb\u5165\u9875\u9762\u4f1a\u51fa\u73b0\u6388\u6743\u5f39\u7a97\uff08\u5982\u4e0b\u56fe\uff09<\/h3> \n

\"\"<\/p> \n

  \u70b9\u51fb\u5141\u8bb8\u5c31\u53ef\u4ee5\u83b7\u53d6\u5230\u7ecf\u7eac\u5ea6\u4e86<\/h3> \n

\"\"<\/p> \n

 \u5982\u679c\u62d2\u7edd\u6388\u6743\u4f4d\u7f6e\u4fe1\u606f\u7684\u8bdd\u5c31\u4f1a\u51fa\u73b0\u5f39\u7a97\u8fdb\u884c\u63d0\u9192\uff0c\u63d0\u9192\u5185\u5bb9\u53ef\u4ee5\u81ea\u5df1\u66f4\u6539\u3002<\/h3> \n

\"\"<\/p> \n

 \u8fd9\u4e2a\u65f6\u5019\u70b9\u51fb\u5f39\u7a97\u7684\u6388\u6743\u4f1a\u8fdb\u5165\u8bbe\u7f6e\u9875\u9762\uff0c\u5141\u8bb8\u4f4d\u7f6e\u4fe1\u606f\u518d\u8fd4\u56de\u5c31\u53ef\u4ee5\u83b7\u53d6\u5230\u7ecf\u7eac\u5ea6\u4e86<\/h3> \n

\"\"<\/p> \n

\u7279\u522b\u6ce8\u610f\uff1a<\/h3> \n

uni.openSetting\u8c03\u8d77\u5ba2\u6237\u7aef\u5c0f\u7a0b\u5e8f\u8bbe\u7f6e\u754c\u9762\uff0c\u8fd4\u56de\u7528\u6237\u8bbe\u7f6e\u7684\u64cd\u4f5c\u7ed3\u679c\uff0c\u6b64api\u53ea\u80fd\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u4f7f\u7528<\/h3> \n

uni.authorize\u67e5\u770b\u662f\u5426\u5df2\u6388\u6743api\u53ea\u80fd\u5728\u5fae\u4fe1\u3001\u767e\u5ea6\u3001\u5b57\u8282\u3001\u98de\u4e66\u3001\u5feb\u624b\u3001QQ\u5c0f\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/h3> \n

\u4e14\u9700\u8981\u5728\u5fae\u4fe1\u5e73\u53f0\u5f00\u901a\uff0c\u5e76\u5728\u914d\u7f6e\u6587\u4ef6\u91cc\u8bbe\u7f6e<\/h3> \n

\"\"<\/p> \n

\n
\t\t"usingComponents": true,\n\t\t"permission": {\n\t\t\t"scope.userLocation": {\n\t\t\t\t"desc": "\u4f60\u7684\u4f4d\u7f6e\u4fe1\u606f\u5c06\u7528\u4e8e\u548c\u95e8\u5e97\u7684\u8ddd\u79bb\u957f\u5ea6"\n\t\t\t}\n\t\t},\n\t\t"requiredPrivateInfos": [\n\t\t\t"getLocation",\n\t\t\t"chooseLocation"\n\t\t]<\/pre> \n <\/div> \n 

2.uni.chooseLocation \u8c03\u8d77\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u83b7\u53d6\u8be6\u7ec6\u5730\u5740<\/span><\/h2> \n

\u5148\u770b\u4ee3\u7801<\/span><\/h3> \n
\n
getMapLocation(){\n\tuni.chooseLocation({\n\t\tsuccess:(res)=> {\n\t\t\tconsole.log(res);\n\t\t\t\/\/ this.getRegionFn(res);\n\t\t},\n\t\tfail:()=>{\n\t\t\t\/\/ \u5982\u679c\u7528uni.chooseLocation\u6ca1\u6709\u83b7\u53d6\u5230\u5730\u7406\u4f4d\u7f6e\uff0c\u5219\u9700\u8981\u83b7\u53d6\u5f53\u524d\u7684\u6388\u6743\u4fe1\u606f\uff0c\u5224\u65ad\u662f\u5426\u6709\u5730\u7406\u6388\u6743\u4fe1\u606f\n\t\t\tuni.getSetting({\n\t\t\t\tsuccess: (res) => {\n\t\t\t\t\tconsole.log(res);\n\t\t\t\t\tvar status = res.authSetting;\n\t\t\t\t\tif(!status['scope.userLocation']){\n\t\t\t\t\t\/\/ \u5982\u679c\u6388\u6743\u4fe1\u606f\u4e2d\u6ca1\u6709\u5730\u7406\u4f4d\u7f6e\u7684\u6388\u6743\uff0c\u5219\u9700\u8981\u5f39\u7a97\u63d0\u793a\u7528\u6237\u9700\u8981\u6388\u6743\u5730\u7406\u4fe1\u606f\n\t\t\t\t\t\tuni.showModal({\n\t\t\t\t\t\t\ttitle:"\u662f\u5426\u6388\u6743\u5f53\u524d\u4f4d\u7f6e",\n\t\t\t\t\t\t\tcontent:"\u9700\u8981\u83b7\u53d6\u60a8\u7684\u5730\u7406\u4f4d\u7f6e\uff0c\u8bf7\u786e\u8ba4\u6388\u6743\uff0c\u5426\u5219\u5730\u56fe\u529f\u80fd\u5c06\u65e0\u6cd5\u4f7f\u7528",\n\t\t\t\t\t\t\tsuccess:(tip)=>{\n\t\t\t\t\t\t\t\tif(tip.confirm){\n\t\t\t\t\t\t\t\t\/\/ \u5982\u679c\u7528\u6237\u540c\u610f\u6388\u6743\u5730\u7406\u4fe1\u606f\uff0c\u5219\u6253\u5f00\u6388\u6743\u8bbe\u7f6e\u9875\u9762\uff0c\u5224\u65ad\u7528\u6237\u7684\u64cd\u4f5c\n\t\t\t\t\t\t\t\t\tuni.openSetting({\n\t\t\t\t\t\t\t\t\t\tsuccess:(data)=>{\n\t\t\t\t\t\t\t\t\t\t\/\/ \u5982\u679c\u7528\u6237\u6388\u6743\u4e86\u5730\u7406\u4fe1\u606f\u5728\uff0c\u5219\u63d0\u793a\u6388\u6743\u6210\u529f\n\t\t\t\t\t\t\t\t\t\t\tif(data.authSetting['scope.userLocation']===true){\n\t\t\t\t\t\t\t\t\t\t\t\tuni.showToast({\n\t\t\t","orderid":"0","title":"uniapp \u5fae\u4fe1\u5bf9\u63a5\u5730\u56fe\u7684\u4e09\u79cd\u64cd\u4f5c(\u4e00)","smalltitle":"","mid":"0","fname":"\u5176\u5b83","special_id":"0","bak_id":"0","info":"0","hits":"105","pages":"2","comments":"0","posttime":"2023-07-26 08:17:40","list":"1690330660","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"uniapp<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"119.59.235.169","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"uniapp \u5fae\u4fe1\u5bf9\u63a5\u5730\u56fe\u7684\u4e09\u79cd\u64cd\u4f5c","lastview":"1714742104","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}