<template>
	<view>
		<map id="myMap" style="width: 750rpx;height: 80vh;" :markers="markers" :longitude="longitude" :latitude="latitude"
		 @tap="onTap">
		</map>
		<view class="">
			请双击定位<br>
			{{addressData.address}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				markers: [], //标记点
				latitude: 0,
				longitude: 0,
				createMap: "",
				touch: false,
				addressData:''
			};
		},
		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				this.inBack()
			}
		},
		created() {
			let that = this
			uni.getLocation({
				type: 'gcj02',
				geocode: true,
				success(res) {
					that.latitude = res.latitude
					that.longitude = res.longitude
					let point = new plus.maps.Point(that.longitude, that.latitude);
					plus.maps.Map.reverseGeocode(
						point, {},
						function(event) {
							that.addressData= event;
						},
						function(e) {}
					);
					that.markers = [{
						id: 1,
						latitude: res.latitude,
						longitude: res.longitude,
						iconPath: '/static/sailun/gps-icon.png',
					}]
				}
			});
		},
		onReady() {
			this.createMap = uni.createMapContext('myMap', this);
		},
		methods: {
			inBack() {
				uni.$emit("addressData", this.addressData)
				uni.navigateBack({})
			},
			onTap(e) {
				console.log(e)
				if (e.type == 'click') {
					let that = this;
					this.createMap.getCenterLocation({
						success(res) {
							console.log(res)
							that.latitude = res.latitude
							that.longitude = res.longitude
							that.markers = [{
								id: 1,
								latitude: that.latitude,
								longitude: that.longitude,
								iconPath: '/static/sailun/gps-icon.png',
							}]
							let point = new plus.maps.Point(res.longitude, res.latitude);
							plus.maps.Map.reverseGeocode(
								point, {},
								function(event) {
									that.addressData= event;
								},
								function(e) {}
							);
						}
					})
				}
			},

		},

	}
</script>

<style lang="scss">

</style>
