php实现手机定位功能的实例
最近在做通过定位手机用户,进行消息推送,经过分析最终做法如下
mobile.php文件(推荐学习:PHP编程从入门到精通)
当用户当手机访问该页面时,通过实现页面表单隐藏封装自动提交获取手机浏览器经纬度并post给服务器
立即学习“PHP免费学习笔记(深入)”;
登录后复制 var position_option = { enableHighAccuracy: true, maximumAge: Infinity, timeout: 100000 }; var lat; var lng; if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(getPositionSuccess, getPositionError, position_option); }else{ alert('Geolocation is not supported by this browser.'); } function getPositionSuccess(position) { lat = position.coords.latitude; lng = position.coords.longitude; //alert('您所在的位置: 纬度' + lat + ',经度' + lng);fillForm(); //填充表单document.form1.submit();//post数据到服务器 } function getPositionError(error) { switch (error.code) { case error.TIMEOUT: alert('The request to get user location timed out.');break; case error.PERMISSION_DENIED: alert('User denied the request for Geolocation.');break; case error.POSITION_UNAVAILABLE: alert('Location information is unavailable.');break; default: alert('An unknown error occurred.'); } } function fillForm(){ document.getElementById('lat').value = lat; document.getElementById('lng').value = lng; }located.php文件通过百度定位api进行解析定位
以上就是php如何获取手机位置的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2525355.html