|
发表于 2015-2-26 15:02:41
|
显示全部楼层
本帖最后由 暗夜的忧伤 于 2015-2-26 15:03 编辑
- Model.prototype.modelLoad = function(event) {
- var data = this.comp('main');
- data.clear();
- data.newData({
- index : 0
- });
- var me = this;
- var load = document.createElement("script");
- load.src = "http://api.map.baidu.com/api?v=2.0&ak=EzfQTH533pbevnhohMX4QZRK";
- document.head.appendChild(load);
- document.addEventListener("deviceready", onDeviceReady, false);
- function onDeviceReady() {
- me.comp("contentData").setValue("title", '获取设备位置信息');
- me.comp("contentData").setValue("x", '经度: ');
- me.comp("contentData").setValue("y", '维度: ');
- me.comp("recordButton").set({
- disabled : false
- });
- function onSuccess(position) {
- me.comp("contentData").setValue("x", position.coords.longitude);
- me.comp("contentData").setValue("y", position.coords.latitude);
- me.getPosition({
- "x" : position.coords.longitude,
- "y" : position.coords.latitude
- });
- }
- function onError() {
- me.comp("contentData").setValue("x", "");
- me.comp("contentData").setValue("y", '');
- }
- navigator.geolocation.getCurrentPosition(onSuccess, onError);
- }
- };
- // 经纬度转换为位置信息
- Model.prototype.getPosition = function(event) {
- var me = this;
- // 创建地理编码实例
- var myGeo = new BMap.Geocoder();
- // 根据坐标得到地址描述
- myGeo.getLocation(new BMap.Point(event.x, event.y), function(result) {
- if (result) {
- me.comp('main').setValue("address", result.address);
- }
- });
- }
复制代码
有很大的误差 |
评分
-
查看全部评分
|