mui框架混合app关于定位问题
2017-06-14 14:47
260 查看
第一次做app,经验并不丰富,碰见的第一个难题就是定位的问题用mui来定位的话偏差太大,最后只能选择百度的,通过手机GPS获取经纬度,然后给百度纠正一下,最后拿到的就是准确的坐标;注明(并不是手机gps不准,是因为国内的政策,怕是一些不法分子干一些坏事,所以故意搞得偏差,还好有百度,高德也可以的),但是百度的秘钥每天访问次数是有限制的;所以你做的app如果用户群体大的话,那还是建议花钱买商业版付费的;
上代码:
还有在html里边要写上script 标签来写你的秘钥这里就不多说了
js代码
function ininMap() {
map = new BMap.Map("container"); //创建一个地图实例,HTML容器包含地图
var point = new BMap.Point(currentX, currentY);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom();
map.addControl(new BMap.GeolocationControl()); // 定位控件
var geolocation = new BMap.Geolocation(); //百度包装好的定位库
geolocation.getCurrentPosition(function(r) {
if(this.getStatus() == BMAP_STATUS_SUCCESS) {
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
currentX = r.point.lng;
currentY = r.point.lat;
console.log('您的位置:' + r.point.lng + ',' + r.point.lat);
var myGeo = new BMap.Geocoder();
// 根据坐标得到地址描述
myGeo.getLocation(new BMap.Point(currentX, currentY), function(result) {
if(result) {
// alert(result.address);
var adress = result.address;
//读取服务器数据
var param = {
"lgtd": currentX,
"lttd": currentY,
"userid": loginUserId,
"identity": Identity,
"position": adress
};
ajax(url, param, function(data) {
console.log("发送成功了")
});
}
console.log(result.address)
});
} else {
alert('failed' + this.getStatus());
}
}, {
enableHighAccuracy: true
});
}
上代码:
还有在html里边要写上script 标签来写你的秘钥这里就不多说了
js代码
function ininMap() {
map = new BMap.Map("container"); //创建一个地图实例,HTML容器包含地图
var point = new BMap.Point(currentX, currentY);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom();
map.addControl(new BMap.GeolocationControl()); // 定位控件
var geolocation = new BMap.Geolocation(); //百度包装好的定位库
geolocation.getCurrentPosition(function(r) {
if(this.getStatus() == BMAP_STATUS_SUCCESS) {
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
currentX = r.point.lng;
currentY = r.point.lat;
console.log('您的位置:' + r.point.lng + ',' + r.point.lat);
var myGeo = new BMap.Geocoder();
// 根据坐标得到地址描述
myGeo.getLocation(new BMap.Point(currentX, currentY), function(result) {
if(result) {
// alert(result.address);
var adress = result.address;
//读取服务器数据
var param = {
"lgtd": currentX,
"lttd": currentY,
"userid": loginUserId,
"identity": Identity,
"position": adress
};
ajax(url, param, function(data) {
console.log("发送成功了")
});
}
console.log(result.address)
});
} else {
alert('failed' + this.getStatus());
}
}, {
enableHighAccuracy: true
});
}
相关文章推荐
- 关于混合app 开发框架Ionic
- 关于mui框架中onclick、href标签失效问题
- 关于App涉及后台定位在审核时二进制文件被拒问题解决方案
- 关于appium操作真机打开app之后无法定位页面元素的问题的解决办法
- 关于robotframework,app,appium的xpath定位问题及常用方法
- 基于mui前端框架开发APP问题总结
- 转:关于我使用spring mvc框架做文件上传时遇到的问题
- 关于ASP.NET页面里框架导致UpdatePanel失效的问题
- 关于div的定位显示问题
- 关于AppDomain 创建实例进行程序集之间的通讯问题
- 关于Silverlight2 beta2 app添加wcf引用的一个小问题
- 关于中小规模生产销售型应用技术框架的想法和问题,请大家多多提点
- 关于frameset框架之间传值问题
- 关于run a dll as an app的问题
- 关于“无法定位程序输入点getaddrinfo于动态链接库WS32_32.dll上”的问题
- 关于网页元素的定位问题及offsetParent的讨论
- 关于matlab与c#混合编程产生的移植问题
- CSS中关于定位position的问题,blockquote,div,span三个的区别
- 一个关于nvarchar字段排序,中英文混合排序的问题
- 关于在struts 框架中使用Filter过滤器解决汉字编码问题