定位接口 //定位城市function getcurrencity(successcall, errorcall) { var city_id = localStorage["city_id"]; if (typeof (city_id) == "undefined") { var browser = getbrowser(); //区分支付宝和微信 if (browser == 'alipay') { alip
//定位城市 function getcurrencity(successcall, errorcall) { var city_id = localStorage["city_id"]; if (typeof (city_id) == "undefined") { var browser = getbrowser(); //区分支付宝和微信 if (browser == 'alipay') { alipaygetcity(successcall, errorcall); } else { wechatgetcity(successcall, errorcall); } } } //支付宝定位 function alipaygetcity(successcall, errorcall) { ap.getLocation(function(res) { if (res.error == 12 || res.error == 13 || res.error == 14 || res.error == 15) { //城市定位失败 errorcall.call(); } else if (res.error == 16) { $.alert('您取消了定位,请选择当前城市', function() { selectCity(); $(".close-city").addClass('hidden'); }); } else { successcall.call(this, res); } }); } //微信定位 function wechatgetcity(successcall, errorcall) { wx.ready(function() { wx.getLocation({ type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function(res) { successcall.call(this, res); }, fail: function() { //城市定位失败 errorcall.call(); }, cancel: function() { $.alert('您取消了定位,请选择当前城市', function() { selectCity(); $(".close-city").addClass('hidden'); }); } }); }); } getcurrencity(successcall, errorcall);