6***@qq.com
6***@qq.com
  • 发布:2018-10-18 11:15
  • 更新:2018-10-18 12:46
  • 阅读:1723

地图getRegion第二次打开报错

分类:uni-app
var map = uni.createMapContext('map');  
			map.getRegion({  
				success: function(res) {  
					console.log(JSON.stringify(res));  
				},  
				fail: (data, code) => {  
					console.log('fail' + JSON.stringify(data));  
				}  
			});

地图获取当前地图的视野范围 第一次打开可以获取到,回退重新打开这个页面就报错了,小程序没问题,真机测试有问题

2018-10-18 11:15 负责人:无 分享
已邀请:
Trust

Trust - 少说废话

第一次打开页面没问题,退出再进,就会报错。
是这个操作流程吧,请确认下。

首页->有地图的页面->调用API->返回->再次打开有地图的页面->调用API。
按照这个步骤操作,没有重现问题,始终走的 success。

6***@qq.com

6***@qq.com (作者)

<template>  
	<view class="map">  
		<map id="map" :latitude="latitude" :longitude="longitude" :markers="covers">  
		</map>  
	</view>  
</template>  
<script>  
	export default {  
		data() {  
			return {  
				title: 'map',  
				latitude: 28.204039,  
				longitude: 112.985415,  
				covers: []  
			}  
		},  
		onLoad() {  
  
			var map = uni.createMapContext('map');  
			map.getRegion({  
				success: function(res) {  
					console.log(JSON.stringify(res));  
				},  
				fail: (data, code) => {  
					console.log('fail' + JSON.stringify(data));  
				}  
			});  
		},  
		methods: {  
			//点击标记  
			makertap: function(e) {  
				console.log("1");  
			},  
			//点击气泡  
			callouttap: function(e) {  
				console.log("2");  
			},  
			//地图视野发生变化  
			regionchange: function(e) {  
				console.log("3");  
			}  
		},  
		components: {  
  
		}  
	}  
</script>  
<style>  
	.map {  
		width: 100%;  
		position: fixed;  
		top: 0;  
		bottom: 0;  
		text-align: center;  
		background: #FFFFFF;  
	}  
  
	map {  
		width: 100%;  
		height: 100%;  
	}  
</style>

操作流程没错,我把代码放上来
错误代码是
11:56:52.773 [ERROR] : thirdScriptError
11:56:52.773 null is not an object (evaluating 'bounds.northease');at pages/list/map onShow function;at setTimeout callback function
11:56:52.773 getBounds@__uniappservice.html:4199:34
11:56:52.773 f8@__uniappservice.html:1:46232
11:56:52.773 N2@__uniappservice.html:1:84364
11:56:52.773 m1L@__uniappservice.html:1:86426
11:56:52.773 s1L@__uniappservice.html:1:86906
11:56:52.773 q5b@__uniappservice.html:1:220409
11:56:52.773 W7o@__uniappservice.html:1:221750
11:56:52.773 value@__uniappservice.html:1:358215
11:56:52.773 __uniappservice.html:1:358529
11:56:52.773 __uniappservice.html:1:249941
11:56:52.773 __uniappservice.html:1:356458
11:56:52.773 __uniappservice.html:1:220951
11:56:52.774 g1L@__uniappservice.html:1:87391
11:56:52.774 C4@__uniappservice.html:1:84217
11:56:52.774 __uniappservice.html:1:273
11:56:52.774 __uniappservice.html:1:193351
11:56:52.774 __uniappservice.html:1:398729

  • Trust

    也没报错,只是获取太早的话会先报地图未初始化完成。


    2018-10-18 12:47

  • 6***@qq.com (作者)

    是的 需要延迟,我延迟了 就没问题了


    2018-10-18 13:31

该问题目前已经被锁定, 无法添加新回复