根据店铺位置信息跳到网页或者app导航
var fdata = { baiduGpsLat:"{$shop.shop_latitude}", baiduGpsLog:"{$shop.shop_longitude}", name:"{$shop.shop_name}", address:"{$shop.shop_position}" }; baiduConfig = { scheme_Android: 'bdapp://map/marker?location='+fdata.baiduGpsLat+','+fdata.baiduGpsLog+'&title='+fdata.name+'&content='+fdata.address, scheme_IOS: 'baidumap://map/marker?location='+fdata.baiduGpsLat+','+fdata.baiduGpsLog+'&title='+fdata.name+'&content='+fdata.address, scheme_web: 'http://api.map.baidu.com/marker?location='+fdata.baiduGpsLat+','+fdata.baiduGpsLog+'&title='+fdata.name+'&content='+fdata.address+'&output=html' }; var timeout = 600; // 判断操作系统,返回百度的不同操作系统下的接口 function adjustOS(){ var ua = window.navigator.userAgent.toLowerCase(); return (ua.indexOf('os') > 0) ? baiduConfig.scheme_IOS : baiduConfig.scheme_Android } function openClient() { var startTime = Date.now(); var ifr = document.createElement('iframe'); ifr.src = adjustOS(); ifr.style.display = 'none'; document.body.appendChild(ifr); var t = setTimeout(function() { var endTime = Date.now(); if (!startTime || endTime - startTime < timeout + 200) { window.location.href = baiduConfig.scheme_web; } }, timeout); window.onblur = function() { clearTimeout(t); } }
首先,上面的一段代码定义了一个函数"openClient()",触发该函数就会跳转到app或者网页(有百度地图app就跳app否则跳网页),只需要在你的网页中插入一个按钮并绑定这个函数即可,位置信息由接口或者模板引擎绑定参数获得。