- 在Hbuilder中uni.getLocation获得经纬度函数使用方式如下
uni.getLocation({
type: 'wgs84',
success: function(res) {
_this.location = res.longitude + ',' + res.latitude;
_this.longitude = res.longitude;
_this.latitude = res.latitude;
}
}
默认情况下如果获得wgs84坐标体系,只要配置maps选项就可以如下配置
2. 实际中百度,高德地图都是以gcj02坐标体系进行定位。因此我们必须获取gcj02坐标体系。获取gcj坐标体系,需要引入定位sdk以及配置正确的。具体部署如下
代码参数修改
uni.getLocation({
type: 'gcj02',
success: function(res) {
_this.location = res.longitude + ',' + res.latitude;
_this.longitude = res.longitude;
_this.latitude = res.latitude;
}
}
2.1 生成打包证书。 我就是因为习惯性使用公共证书打包,导致获取gcj02坐标一直提示key失败
步骤一:证书,生成过程中需要记住别名,证书密码
keytool -genkey