起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2062|回复: 2

[处理中3] 微信获取不到当前的位置

[复制链接]

17

主题

38

帖子

126

积分

初级会员

Rank: 2

积分
126
QQ
发表于 2016-9-13 17:29:24 | 显示全部楼层 |阅读模式
define(function(require){
                var $ = require("jquery");
        var justep = require("$UI/system/lib/justep");
        var Baas = justep.Baas;
        var CommonUtils = require("$UI/system/components/justep/common/utils");
        var bmap = require('$UI/system/components/justep/bmap/bmap');
       
        require("$UI/system/lib/cordova/cordova");
        require("cordova!cordova-plugin-device");
        require("cordova!com.justep.cordova.plugin.weixin.v3");
        require("cordova!com.justep.cordova.plugin.alipay");
       
        require("cordova!cn.jpush.phonegap.JPushPlugin");
        require("cordova!com.justep.cordova.plugin.unionpay");
        require("res!./img");
               
        require("cordova!cordova-plugin-geolocation");
        require("cordova!com.justep.cordova.plugin.baidulocation");
       
        var Model = function() {
                /*this.callParent();
                this.arr = [];*/
                this.callParent();

                this._deviceType = "pc"; // pc || wx || app

                this._userID = "user";
                this._userDefaultName = "新用户";
                this._userDefaultAddress = "";
                this._userPhotoURL = "";
        };
       
Model.prototype.locationClick = function(event) {
                        var me =this;
                       
                        //this.wxApi = new navigator.WxApi("wx799221c9cb7cd688");
                       
                        if (this.wxApi) {
                        this.wxApi.exec().done(function(wx) {
                                wx.getLocation({
                                        type : "gcj02",
                                        success : function(data) {
                                                wx.openLocation({
                                                        latitude : data.latitude,
                                                        longitude : data.longitude,
                                                        name : '',
                                                        address : '当前位置',
                                                        scale : 14,
                                                        infoUrl : 'http://wex5.com'
                                               
                                                })
                                               
                                        },
                                        cancel : function(res) {
                                               
                                        }
                                });
                        }).fail(function() {
                               
                        });
                } else {
       
                        function successCallback(position){
                                //debugger;
                               
                                 justep.Util.hint(position.address);
                              me.comp("windowDialog1").open({
                                        data : {
                                                latitude : position.coords.latitude,
                                                longitude : position.coords.longitude
                                        }
                               });
                                 alert("地址" + position.address +"坐标系" + position.coorType+ "纬度" + position.coords.latitude+"经度" + position.coords.logitude);
                                /*alert("地址" + position.address);
                                alert("坐标系" + position.coorType);
                                alert("纬度" + position.coords.latitude);
                                alert("经度" + position.coords.logitude);*/
                                //me.comp("windowDialog1").open({data:JSON.stringify(position)});
                       
                        }
                        function errorCallback(position){
                                alert("失败");
                       
                        }
                       
                        navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
                }
        };
      Model.prototype.getLocation = function() {
                var gpsDtd = $.Deferred();
                if (this.wxApi) {
                        this.wxApi.exec().done(function(wx) {
                                wx.getLocation({
                                        type : "gcj02",
                                        success : function(data) {
                                                gpsDtd.resolve({
                                                        coorType : data.coorType,
                                                        address : data.address,
                                                        longitude : data.longitude,
                                                        latitude : data.latitude
                                                });
                                        },
                                        cancel : function(res) {
                                                gpsDtd.resolve({
                                                        longitude : 116.45764191999997,
                                                        latitude : 39.8622934399999
                                                });
                                        }
                                });
                        }).fail(function() {
                                gpsDtd.resolve({
                                        longitude : 116.45764191999997,
                                        latitude : 39.8622934399999
                                });
                        });
                } else if (navigator.geolocation) {
                        var success = function(data) {
                                // data.longtitude 经度
                                // data.latitude 纬度
                                // data.address 文字描述的地址信息
                                // data.hasRadius 是否有定位精度半径
                                // data.radius 定位精度半径
                                // data.type 定位方式
                                // data.coorType
                                gpsDtd.resolve({
                                        coorType : data.coorType,
                                        address : data.address,
                                        longitude : data.coords.longitude,
                                        latitude : data.coords.latitude
                                });
                        };

                        var fail = function(e) {
                                justep.Util.hint("获取地理位置失败,暂时采用默认地址");
                                gpsDtd.resolve({
                                        longitude : 116.45764191999997,
                                        latitude : 39.8622934399999
                                });
                        };
                        /**
                         *  如果在室内 enableHighAccuracy: true 反而误差更大
                         *  如果在室外 enableHighAccuracy: true 相对准确
                         */
                        navigator.geolocation.getCurrentPosition(success, fail);
                        /*var gpsWatchID = navigator.geolocation.watchPosition(success, fail,{
                        timeout: 30*1000,
                        maximumAge: 30000,
                        enableHighAccuracy: true});*/
                } else {
                        justep.Util.hint("获取地理位置失败,暂时采用默认地址");
                        gpsDtd.resolve({
                                longitude : 116.45764191999997,
                                latitude : 39.8622934399999
                        });
                }
                return gpsDtd.promise();
        };


        return Model;
});










报错信息

报错信息

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36178
发表于 2016-9-14 18:39:58 | 显示全部楼层
运行平台默认的外卖正确吗?
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

17

主题

38

帖子

126

积分

初级会员

Rank: 2

积分
126
QQ
 楼主| 发表于 2016-9-21 12:48:33 | 显示全部楼层
结帖
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2025-6-17 04:46 , Processed in 0.073664 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表