(function () { var page = { init: function ($page, param) { console.log('~~~~~~~~~~~~'); console.log(param); var geocoder = null; var originName='';//北四环东路 望和路 var origin = new Array();//origin[0]为纬度,origin[1]为经度 if(param.startEnd.start){ var start = param.startEnd.start; origin = new Array(start.lat, start.lng) if(!geocoder){ geocoder = new AMap.Geocoder({ radius: 50 }); } geocoder.getAddress(start, function(status, result) { if (status === 'complete' && result.regeocode) { var address = result.regeocode.formattedAddress; originName = address; }else{console.log(JSON.stringify(result))} }); } var destinationName = param.endAddress; var destination=new Array(param.startEnd.end.lat, param.startEnd.end.lng);//目的地纬度、经度。先纬度后经度 renlian.layer.loading(true, "加载数据中"); //地图初始化 var map = new AMap.Map("navigation-map", { resizeEnable: true, center: [113.955439, 22.542956],//地图中心点 zoom: 12 //地图显示的缩放级别 }); var mapList = [ { value: "com.baidu.BaiduMap", text: "百度地图", }, { value: "com.autonavi.minimap", text: "高德地图", }, { value: "com.tencent.map", text: "腾讯地图", }, { value: "com.google.android.apps.maps", text: "谷歌地图", } ]; map.on('complete', function(){ renlian.layer.loading(false); }); if(!param.startEnd.start){ renlian.layer.toast('无法获取定位点'); } var riding = null; var userMarker = new AMap.Marker({icon: "./images/location.png", offset:new AMap.Pixel(-16, -16)}); //骑行导航 if(!riding){ var riding = new AMap.Riding({ map: map, autoFitView: true }); } //根据起终点坐标规划骑行路线 riding.search(param.startEnd.start, param.startEnd.end, function(status, result) { if (status === 'complete') { } else { renlian.layer.toast('骑行路线数据查询失败:' + result); } }); var presentLnglat = null; function get_mobile_gps_location(onSuccess,onError){ var onSuccess = function(position) { // alert('Latitude: ' + position.coords.latitude + '\n' + // 'Longitude: ' + position.coords.longitude + '\n' + // 'Altitude: ' + position.coords.altitude + '\n' + // 'Accuracy: ' + position.coords.accuracy + '\n' + // 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' + // 'Heading: ' + position.coords.heading + '\n' + // 'Speed: ' + position.coords.speed + '\n' + // 'Timestamp: ' + position.timestamp + '\n'); var gps = [position.coords.longitude, position.coords.latitude]; AMap.convertFrom(gps, 'gps', function (status, result) { if (result.info === 'ok') { var lnglats = result.locations; // Array. } presentLnglat = new AMap.LngLat(lnglats[0].lng, lnglats[0].lat); userMarker.setPosition(presentLnglat); userMarker.setMap(map); }); }; function onError(error) { console.log('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } navigator.geolocation.getCurrentPosition(onSuccess, onError); } get_mobile_gps_location(); var locationAuto = setInterval(function(){ if($('.f-page').length < 2){ clearTimeout(locationAuto); } if(!window.lrmui.isreal){ get_mobile_gps_location(); var lnglat = presentLnglat; if(!geocoder){ geocoder = new AMap.Geocoder({ radius: 50 }); } origin = new Array(lnglat.lat, lnglat.lng); geocoder.getAddress(lnglat, function(status, result) { if (status === 'complete' && result.regeocode) { var address = result.regeocode.formattedAddress; originName = address; $('#navg-address').text(address); }else{console.log(JSON.stringify(result))} }); } }, 6000); function haveInstalledApp(){//通过包名判断app是否安装 var mapList = document.getElementsByClassName('mapLi'); var baiduPackageName = "com.baidu.BaiduMap"; var gaodePackageName = "com.autonavi.minimap"; var tengxunPackageName = "com.tencent.map"; var gugePackageName = "com.google.android.apps.maps"; appAvailability.check(baiduPackageName,function () {//success callback mapList.item(0).style.display = 'block'; },function () {// mapList.item(0).style.display = 'none'; }); appAvailability.check(gaodePackageName,function () {//success callback mapList.item(1).style.display = 'block'; },function () {// mapList.item(1).style.display = 'none'; }); appAvailability.check(tengxunPackageName,function () {//success callback mapList.item(2).style.display = 'block'; },function () {// mapList.item(2).style.display = 'none'; }); appAvailability.check(gugePackageName,function () {//success callback mapList.item(3).style.display = 'block'; // mapList.item(4).style.display = 'block'; },function () { mapList.item(3).style.display = 'none'; }); } $('#daohang-button').rlpicker({ data: mapList },function(map){ appAvailability.check(map,function () {//success callback if(!origin){ renlian.layer.toast('无法获取定位点'); get_mobile_gps_location(); return; } if(map == 'com.baidu.BaiduMap'){ checkBaidu(); } if(map == 'com.autonavi.minimap'){ checkGaode(); } if(map == 'com.tencent.map'){ checkTengxun(); } if(map == 'com.google.android.apps.maps'){ checkGuge(); } },function () {// renlian.layer.warning('未检测到安装了该地图应用', function () { }, '提示', '确定'); }); }); // function checkBaidu(){ var sApp = startApp.set({ /* params */ "action":"ACTION_VIEW", "category":"CATEGORY_DEFAULT", "type":"text/css", "package":"com.baidu.BaiduMap", "uri":"baidumap://map/direction?origin=name:"+originName+"|latlng:"+origin[0]+","+origin[1]+"&destination=name:"+destinationName+"|latlng:"+destination[0]+","+destination[1]+"&mode=driving", "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], "intentstart":"startActivity" }); sApp.start(function() { /* success */ //alert("OK"); }, function(error) { /* fail */ alert(error); }); } function checkGaode(){ var sApp = startApp.set({ /* params */ "action":"ACTION_VIEW", "category":"CATEGORY_DEFAULT", "type":"text/css", "package":"com.autonavi.minimap", "uri":"amapuri://route/plan/?slat="+origin[0]+"&slon="+origin[1]+"&sname="+originName+"&dlat="+destination[0]+"&dlon="+destination[1]+"&dname="+destinationName+"&dev=0&t=0", "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], "intentstart":"startActivity" }); sApp.start(function() { /* success */ //alert("OK"); }, function(error) { /* fail */ alert(error); }); } function checkTengxun(){ var sApp = startApp.set({ /* params */ "action":"ACTION_VIEW", "category":"CATEGORY_DEFAULT", "type":"text/css", "package":"com.tencent.map", "uri":"qqmap://map/routeplan?type=drive&from="+originName+"&fromcoord="+origin[0]+","+origin[1]+"&to="+destinationName+"&tocoord="+destination[0]+","+destination[1]+"&coord_type=1&policy=0", "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], "intentstart":"startActivity" }); sApp.start(function() { /* success */ //alert("OK"); }, function(error) { /* fail */ alert(error); }); } function checkGuge(){//指定终点经纬度,默认当前位置 var sApp = startApp.set({ /* params */ "action":"ACTION_VIEW", "category":"CATEGORY_DEFAULT", "type":"text/css", "package":"com.google.android.apps.maps", "uri":"google.navigation:q="+destination[0]+","+destination[1], "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], "intentstart":"startActivity" }); sApp.start(function() { /* success */ //alert("OK"); }, function(error) { /* fail */ alert(error); }); } }, reload:function(pageinfo){ console.log('testsfadfasd') } }; return page; })();