按顺序引用如下文件:
js/zepto.min.js
js/config.js
js/yeui.js
//启动定位方法如下:
yeui.startLocation();
//接收定位数据的回调函数
//将此下面的方法复制重写yeui.locationBack函数即可
var strCity="";
yeui.locationBack=function(city,lon,lat,isGps)
{
if(city=='')
{
//假如原生定位失败,则调用百度IP定位
//延时1秒钟调用百度浏览器定位
setTimeout(function(){
if(strCity==''&&strCity=='')
{
$.ajax({
url:"http://api.map.baidu.com/location/ip",
type:"post",
dataType:"json",
data:{ak:'你申请的百度IP定位的ak'},
success:function(data){
strCity=data.content.address_detail.city;
},
error: function() {
alert('调用接口出错');
return;
}
});
}
},1000);
}
else if(city!=''){
strCity="原生定位:"+city;
}
}