首页 > 其他分享 >uniapp离线打包总结

uniapp离线打包总结

时间:2023-06-07 14:14:07浏览次数:56  
标签:uniapp positionInfo res 离线 latitude plus var android 打包

uniapp离线打包总结

一、准备好Android Studio的项目外壳,这里采用的是https://nativesupport.dcloud.net.cn/AppDocs/download/android.html#

image-20230607132833071

下载后选用HBbuilder-Integrate-AS作为外壳,如下图所示

image-20230607133323304

二、Android模块配置

按项目所用到的模块进行配置,详情参考官网https://nativesupport.dcloud.net.cn/AppDocs/usemodule/androidModuleConfig/geolocation.html

image-20230607133736098

NOTES:配置定位模块时要注意的地方

一定要引入好对应的包,同时在安卓离线打包时,定位采用的是SDK方式的key,配置key时要注意别配置错了

image-20230607134123798

示例:获取当前位置信息

// 通过自带的方法获取到当前的经纬度,调用方法获取到地址获取到地址的中文信息
			getCurrentLocation() {
				this.$tip.loading('正在定位')
				let that = this //在uniapp中药定义一下this才能使用
				let system = uni.getSystemInfoSync(); // 获取系统信息
				if (system.platform === 'android') { // 判断平台
					var context = plus.android.importClass("android.content.Context");
					var locationManager = plus.android.importClass("android.location.LocationManager");
					var main = plus.android.runtimeMainActivity();
					var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
					if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
						uni.showModal({
							title: '提示',
							content: '请打开定位服务功能',
							showCancel: false, // 不显示取消按钮
							success() {
								if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
									var Intent = plus.android.importClass('android.content.Intent');
									var Settings = plus.android.importClass('android.provider.Settings');
									var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
									main.startActivity(intent); // 打开系统设置GPS服务页面
								} else {
									console.log('GPS功能已开启');
								}
							}
						});
					} else {
						// Android SDK的高德key
						let that = this
						plus.geolocation.getCurrentPosition(function(res) {
							// console.log(res);
							that.$tip.success('定位成功')
							that.positionInfo.address = res.addresses; //当前定位
							that.positionInfo.longitude = res.coords.longitude;
							that.positionInfo.latitude = res.coords.latitude;
							that.allInfo = Object.assign(res.address, res.coords)
							that.formAssign()
							that.givingInfo()
						}, function(e) {
							that.$tip.loaded()
							plus.nativeUI.toast('Geolocation error: ' + e.message);
						}, {
							provider: 'amap',
							coordsType: 'gcj02'
						});
					}
				}

			},
        
// 定位返回的数据结构如下
{
	"type": "gcj02",
	"altitude": 0,
	"latitude": 23.152675,
	"longitude": 113.338533,
	"speed": 0,
	"accuracy": 31,
	"address": {
		"country": "中国",
		"province": "广东省",
		"city": "广州市",
		"district": "天河区",
		"street": "xxx路",
		"streetNum": "xxx号",
		"poiName": "xxx",
		"cityCode": "020"
	},
	"errMsg": "getLocation:ok"
}

(WebApi方式的key获取当前详细地址)

getCurrentLocation() {
				this.$tip.loading('正在定位')
				let that = this //在uniapp中药定义一下this才能使用
				let system = uni.getSystemInfoSync(); // 获取系统信息
				if (system.platform === 'android') { // 判断平台
					var context = plus.android.importClass("android.content.Context");
					var locationManager = plus.android.importClass("android.location.LocationManager");
					var main = plus.android.runtimeMainActivity();
					var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
					if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
						uni.showModal({
							title: '提示',
							content: '请打开定位服务功能',
							showCancel: false, // 不显示取消按钮
							success() {
								if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
									var Intent = plus.android.importClass('android.content.Intent');
									var Settings = plus.android.importClass('android.provider.Settings');
									var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
									main.startActivity(intent); // 打开系统设置GPS服务页面
								} else {
									console.log('GPS功能已开启');
								}
							}
						});
					} else {
						uni.getLocation({
							// type: 'wgs84',
							type: 'gcj02',
							geocode: true, //必须要将geocode配置为true
							isHighAccuracy: true,
							success: function(res) {
								plus.nativeUI.toast('定位服务111'+JSON.stringify(res))
								console.log('当前位置的经度:' + res.longitude);
								console.log('当前位置的纬度:' + res.latitude);
								console.log('当前位置:' + JSON.stringify(res));
								let ret = res.address
								that.positionInfo.longitude = res.longitude;
								that.positionInfo.latitude = res.latitude;
								// that.positionInfo.address = '当前位置是:'+ret.province+ret.city+ret.district+ret.street+ret.streetNum+ret.poiName
								that.loAcquire(that.positionInfo.longitude, that.positionInfo.latitude)
							},
							fail: function(res) {
								plus.nativeUI.toast('定位服务错误'+JSON.stringify(res))
								that.$tip.loaded()
							}
						});
					}
				}

			},
			// 获取当前地址(web API方式的高德key)
			loAcquire(longitude, latitude) {
				let that = this;
				let data = {
					key: '4xxxxxxxxxxxxxx335faa3e1d4174f507',
					location: longitude + ',' + latitude,
					output: 'JSON'
				}
				uni.request({
					url: `https://restapi.amap.com/v3/geocode/regeo`,
					data: data
				}).then(res => {
					console.log('jsonp===', JSON.stringify(res));
					this.$tip.success('定位成功')
					// this.$tip.loaded()
					if (res[1].data.status == 1) {
						that.positionInfo.address = res[1].data.regeocode.formatted_address; //当前定位
						that.allInfo = res[1].data.regeocode
					}
				})
			},

三、导入app本地资源

详情见https://nativesupport.dcloud.net.cn/AppDocs/importfeproject/export.html

后续同样参考官网

标签:uniapp,positionInfo,res,离线,latitude,plus,var,android,打包
From: https://www.cnblogs.com/Plume-blogs/p/17463113.html

相关文章

  • tar打包文件排除项使用
    1、exclude排除参数使用tar-Pczf/tmp/data.tar.gz/data--exclude*.jar--exclude*.war--exclude=/data/jenkins2、注意项a、排除目录需要使用绝对路径b、如果在crontab中使用需要加上转义斜杠,不然排除不生效。如下所示:tar-Pczf/tmp/data.tar.gz/data--excl......
  • 读取FTP文件,并打包成压缩包下载
    importjava.io.*;importjava.net.SocketException;importjava.net.URLEncoder;importjava.util.List;importjava.util.zip.ZipEntry;importjava.util.zip.ZipOutputStream;importorg.apache.commons.net.ftp.FTPClient;importorg.apache.commons.net.ftp.FTPF......
  • uniapp使用uview组件的indexList写选择城市
    <template><viewclass=""><viewclass="top"><viewclass="search-boxmt10flexalcenter"><viewclass="search-input"><u-search:showAction=&q......
  • python打包后,执行报错:NameError: name ‘exit‘ is not defined
    try:file_name=os.path.basename(src)file_size=os.stat(src).st_sizeexceptException:print("源文件不存在:",src)exit()在ide使用中没有问题,但是封装成应用程序时就出现问题: NameError:name'exit'isnotdef......
  • uniapp主题切换功能的第一种实现方式(scss变量+vuex)
    随着用户端体验的不断提升,很多应用在上线的时候都要求做不同的主题,最基本的就是白天与夜间主题。就像b站app主题切换,像这样的uniapp因为能轻松实现多端发布而得到很多开发者的青睐,但每个端的实现也有可能不同,现我把已实现的功能一点点的大家分享给大家,须要的可以参考一下,可......
  • python离线下载安装包
    1.背景内网服务器不能直接连接外网,但是需要Python的mysql-connector-2.1.7包2.步骤#下载相关tar包https://pypi.doubanio.com/simple/mysql-connector/mysql-connector-2.1.7.tar.gz#上传到服务器后,解压tar-zxvfmysql-connector-2.1.7.tar.gz#进入解压目录,安装cdm......
  • uniapp能对接蓝牙打印机吗? 答案是肯定的
    ​答案是肯定的,以下是一个使用“uni-bluetooth-print”插件连接蓝牙打印机的示例代码:1.在项目目录中运行以下命令安装插件:npminstalluni-bluetooth-print2.在代码中导入插件:importbluetoothPrintfrom'uni-bluetooth-print';3.调用 `connect()` 方法连接蓝......
  • Centos7 离线编译安装python3
    一,安装依赖yum-yinstallzlib-develbzip2-developenssl-develncurses-develreadline-develtk-develgccmake安装libffi-devel依赖yuminstalllibffi-devel-y注意:如果不安装这个包,python3可以装成功,但是后面装flask、uwsgi等依赖python3中有个内置模块叫ctype......
  • 手机app打包发布
    今天app已经打包成apk,  ......
  • PyInstaller 完美打包 Python 脚本,输出结构清晰、便于二次编辑的打包程序
    引入问题如果我要写一个Python项目,打包成exe运行(方便在没有Python的电脑上使用),我需要打包出的根目录结构美观,没有多余的、杂乱的依赖文件在那里碍眼,而且需要在发现bug时,我还需要能够修改里面的代码后,无需再次打包,就能正常运行,该怎么做呢?就以一个Hello项目为例,记一下我......