微信小程序调用百度鹰眼地图API问题

map.wxml:



地址:{{oneLatitude}}

map.wxss:

#myMap {
  position: absolute;
  left: 0;
  top:30;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 90%;
}

map.js:

var app = getApp()
Page({
	data: {
		markerId: 0,
		controlId: 0,
		markers: [
			{
				id: 120,
				//		latitude: '22.479726177273',
				//		longitude: '113.90078227654',
				latitude: 'oneLatitude',    //第4步,将赋值的oneLatitude回传给latitude
				longitude: 'oneLongitude',  //第4步,将赋值的oneLongitude回传给longitude
                                               
				iconPath: '/images/公交车.png',
				title: '一号车',
				width: 30,
				height: 20,
				callout: {
					content: '1号车',
					color: '#ffffff',
					display: 'ALWAYS',
					bgColor: '#ff6600',
					borderRadius: '5',
					padding: 2,
				},
			},
			{
				id: 100,
				latitude: 22.535861,
				longitude: 113.942336,
				iconPath: '/images/地图定位.png',
				title: 'W1A总站附近有深大地铁C出口,CES大厦,科技园总部等建筑',
				width: 30,
				height: 30,
				callout: {
					content: 'W1A总站',
					color: '#ffffff',
					display: 'ALWAYS',
					bgColor: '#ff6600',
					borderRadius: '5',
					padding: 2,
				},
			  },
			
		],
	},


	onLoad: function () {
		var oneLatitude = this;    //第1步:新建2个坐标变量
		var oneLongitude = this;   //第1步:新建2个坐标变量
wx.request({
url: 'http://yingyan.baidu.com/api/v3/entity/list', //第2步:访问百度提供的gps设备API坐标地址,已经测试过可以获取到坐标地址。
data: {ak: 'YeXRKvVBD*****2q3RYB2gmDGe',service_id: '16****',},
header: {"Content-Type": "applciation/json"},
method: "GET",

success: function (res) 
{console.log('访问百度地图数据成功')
console.log(res);
console.log(res.data.entities["0"].latest_location.latitude)
console.log(res.data.entities["0"].latest_location.longitude)
oneLatitude = (res.data.entities["0"].latest_location.latitude) //第3步:将百度地址赋值到变量中
oneLongitude = (res.data.entities["0"].latest_location.longitude) //第3步:将百度地址赋值到变量中
				console.log('获得的变量值:')
				console.log(oneLatitude)
				console.log(oneLongitude)
			},
			fail: function () {
				console.log('访问百度地图数据失败')
			}
		});
		



 
  


这是在微信小程序中运行的结果:

微信小程序调用百度鹰眼地图API问题_第1张图片


问题:

如代码逻辑思路是第1.2.3.4步

1、访问百度地图提供的地址API已经获取到了latitude和longitude。

2、如代码所示,我建立了2个var变量oneLatitude和oneLongitude,把获取到的地址赋值到这两个变量中去,但是在地图中不显示相对应的图标(公交车.pnp)出来。我觉得是获取到百度坐标地址后赋值给地图组件,但是前端的地图组件没有刷新,所以没有显示图标,试了很多种方式都没解决,不知道怎么办,还请哪位大神解答一下。

注:坐标地址一定可以用,我直接填写数字是可以显示的。但是引用oneLatitude和oneLongitude就不行。

你可能感兴趣的:(微信小程序调用百度鹰眼地图API问题)