Mobile. PHP file
When the user accesses the page, by implementing the page form hidden Encapsulation Auto-submit to get the latitude and longitude of the mobile browser and post to the server
<HTML><MetaCharSet= "UTF8"><Head><formname= "Form1"Action= "http://test.nwee.cc/ken/baidulocated.php"Method= "POST"><inputtype= "text"name= "Lat"ID= "Lat"style= "Display:none"><inputtype= "text"name= "LNG"ID= "LNG"style= "Display:none"></form><Scripttype= "Text/javascript"> varposition_option={enablehighaccuracy:true, maximumage:infinity, timeout:100000 }; varlat; varLNG; if(navigator.geolocation) {navigator.geolocation.getCurrentPosition (getpositionsuccess, Getpositionerror, Position_option); }Else{alert ('Geolocation is isn't supported by this browser.'); } functiongetpositionsuccess (position) {lat=Position.coords.latitude; LNG=Position.coords.longitude; //alert (' Where you are: Latitude ' + lat + ', longitude ' + LNG);fillform ();//fill out the formdocument.form1.submit ();//Post data to the server } functionGetpositionerror (Error) {Switch(error.code) { Caseerror. Timeout:alert ('The request to get user location timed out.'); Break; Caseerror. Permission_denied:alert ('User denied the request for geolocation.'); Break; Caseerror. Position_unavailable:alert ('Location information is unavailable.'); Break; default: Alert ('An unknown error occurred.'); } } functionFillform () {document.getElementById ('lat'). Value=lat; document.getElementById ('LNG'). Value=LNG; }</Script></Head></HTML>
located.php file
Through the Baidu positioning API for analytic positioning
<? PHP Header ("content-type:text/html; Charset=utf8 "); $url= "http://api.map.baidu.com/geocoder/v2/?location=". $_post ["Lat"]. ",". $_post ["LNG"]. " &ak=*****************************&coordtype=bd09ll&output=json "; $json file_get_contents ($url); $arr = Json_decode ($jsontrue); Var_dump ($arr);? >
PHP for mobile phone positioning