uniapp 定位 android ios

uniapp 定位 android ios

			<view class="cen-style">
				<view class="cens-title">详细地址:</view>
				<view class="fbc">
					<view style="width: 400rpx;"><u-input v-model="address" type="text" :border="false" placeholder="街道,楼牌号等" /></view>
					<u-icon name="map" size="40" @click="getaddress"></u-icon>
				</view>
			</view>
//判断手机是否开启定位功能
checkOpenGPSService() {
			let system = uni.getSystemInfoSync(); // 获取系统信息
    //安卓	android
			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 if (system.platform === 'ios') {    //	ios 系统
				var cllocationManger = plus.ios.import('CLLocationManager');
				var enable = cllocationManger.locationServicesEnabled();
				var status = cllocationManger.authorizationStatus();
				plus.ios.deleteObject(cllocationManger);
				if (enable && status != 2) {
					console.log('手机系统的定位已经打开');
				} else {
					console.log('手机系统的定位没有打开');
					uni.showModal({
						title: '提示',
						content: '请打开定位服务功能',
						showCancel: false, // 不显示取消按钮
						success() {
							var UIApplication = plus.ios.import('UIApplication');
							var application2 = UIApplication.sharedApplication();
							var NSURL2 = plus.ios.import('NSURL');
							// var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
							// var setting2 = NSURL2.URLWithString("App-Prefs:root=LOCATION_SERVICES");
							// var setting2 = NSURL2.URLWithString("app-settings");
							var setting2 = NSURL2.URLWithString('App-Prefs:root=Privacy&path=LOCATION');
							// var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION_SERVICES");
							application2.openURL(setting2);
							plus.ios.deleteObject(setting2);
							plus.ios.deleteObject(NSURL2);
							plus.ios.deleteObject(application2);
						}
					});
				}
			}
		},
            
            
getaddress() {
    		//判断手机是否开启定位功能
			this.checkOpenGPSService();
			let that = this;
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				success: function(res) {
					that.province = res.address.province;
					that.city = res.address.city;
					that.area = res.address.district;
					that.address = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum + res.address.poiName;
					console.log(res.address.city);
				}
			});
		},
            

在这里插入图片描述

<view class="pad">
				<map style="width: 100%; height: 300rpx;" :latitude="latitude" :longitude="longitude" :markers="covers"></map>
				<view class="ipnand" @click="gotoLocation">
					<view class="fc">
						<u-icon name="map-fill" color="#fff" size="28"></u-icon>
						<text class="ipbxassa ellipsis1">{{ covers[0].title }}</text>
					</view>
					<u-icon name="arrow-right" color="#fff" size="28"></u-icon>
				</view>
			</view>	

<script>
gotoLocation() {
			this.$nextTick(() => {
				uni.openLocation({
					latitude: Number(this.covers[0].latitude), //要去的纬度-地址
					longitude: Number(this.covers[0].longitude), //要去的经度-地址
					name: this.covers[0].title, //地址名称
					address: this.covers[0].title, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error);
					}
				});
			});
		}
    </script>

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
HBuilder是一款基于HTML5开发的跨平台集成开发工具,而Uniapp则是HBuilder的一个重要插件,用于开发跨平台应用程序。Uniapp允许开发者使用Vue.js进行开发,并将代码编译生成AndroidiOS应用。 Uniapp提供了一整套的开发工具和组件,可以帮助开发者快速构建跨平台应用。首先,它提供了多个UI组件,如按钮、标签、表单等,可以在应用中快速集成和使用。其次,Uniapp还提供了丰富的API接口,包括网络请求、本地文件操作等功能,使开发者可以轻松地实现各种功能需求。而且,Uniapp还提供了一套完整的调试工具,方便开发者在开发过程中定位和解决问题。 使用HBuilder和Uniapp进行安卓和iOS应用的开发具有很多优势。首先,开发者只需要编写一套代码,就可以同时生成安卓和iOS应用。这样可以大大减少开发时间和成本。而且,Uniapp的代码结构简洁,易于维护和扩展。其次,因为是基于Vue.js开发的,所以开发者可以充分利用Vue.js的各种特性,如数据绑定、组件化等,大大提高开发效率。此外,HBuilder和Uniapp也提供了丰富的文档和教程,为开发者提供了详细的学习和参考资料。 总之,使用HBuilder和Uniapp进行安卓和iOS应用的开发是一种高效和便捷的方式。开发者可以充分利用这些工具和平台提供的功能和资源,快速构建出高质量的跨平台应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

织_网

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值