Home > Mobile >  Tips to get the camera get position, this how to solve
Tips to get the camera get position, this how to solve

Time:10-09


The great god, when acquiring the position using the WeChat public number millet mobile phone use public suggests to use the camera, apple mobile phone can prompt access to normal position, the have met you,
//WeChat initialization complete 
The function wxInit () {
If (cityname==null | | cityname=="" | | cityname==" guangxi ") {
Wx. GetLocation ({//for local latitude and longitude
Type: 'gcj02',//the default value is wgs84 GPS coordinates, if you want to return for openLocation Mars coordinates directly, tencent, Google, Scott coordinates, can be introduced into 'gcj02'
Success: the function (res) {
Lat=res. Latitude;//latitude, floating point Numbers, for the range of 90 - - 90
Lon=res. Longitude;//longitude, floating point Numbers, range is 180 ~ 180,
//5 [default] tencent, Google, Scott coordinates
GetQQCity (" 5 ");
},
Fail: function (res) {
//alert (' user to authorize access to the geographical position);
//initRedList ();
}
});
Wx. CheckJsApi ({
JsApiList: [' getLocation],//need to detect JS interface list, list all JS interface, see appendix 2
Success: the function (res) {
If (res) checkResult) getLocation=="true"
| | res. CheckResult. GetLocation==true) {
} else {
//initRedList ();
Alert (" positioning failed, please check WeChat application Settings ");
}
}
});
}
}
The function getQQCity (coord_type) {
If (lon=="" | | lat==" ") {
//initRedList ();
return;
}
Var fn=function (data) {
Var isCity2=0;
If (data. The status==0) {
//alert (coord_type + "is the check address:" + data. The result, the address).
//cityname=data. Result. Address_component. City. Replace (" city ", "");
Cityname=data. Result. Address_component. City. The substring (0,
2);
Var iscity=0;
for (var i=0; I & lt; CityList. Length; I++) {
If (cityList [I] CITYNAME==CITYNAME) {
CityCode cityList=[I] cityCode;
IsCity2=1;
}
}
If (isCity2==0) {
Lat="";
Lon="";
Cityname="guangxi";
CityCode="0590";
The location. The hash="";
}
$(" # js - cityname "). The text (cityname);
}
If (isCity2==1) {
CurrentPage=0;
EveryPage=5;
$(' in_probox ul '). The empty ();
InitRedList ();
Batch_id="0";
InitSecKill ();
InitRecommend ();
}

};
Var ef=function errinit () {
//initRedList ();
};
Var url="https://apis.map.qq.com/ws/geocoder/v1/";
Var maps={
Output: "json",
"Location" : lat + ", "+ lon,
"Coord_type" : coord_type,
"Key" : "M3JBZ - 7 atwx - RIB4V - ZO5U2 - HWZI2 - VBBTE"
};
AjaxTimeout (url, maps, fn, ef, 3000);
}
The function ajaxTimeout (url, maps, fn, ef, time) {
Var ajaxTimeoutTest=$. Ajax ({
Url: the url,//request url
Timeout: time,//timeout Settings, unit milliseconds
Type: "post",//request methods, get or post
Data: maps,//request parameters, the json format
DataType: 'the json,//return data format
Json: 'callback',
Success: fn,
Error: ef,
Complete: a function (XMLHttpRequest, status) {//request after the completion of the final execution parameter
If (status=='timeout') {//timeout, the status and success, error
the condition of the equivalentAjaxTimeoutTest. Abort ();
Ef ();
}
}
});
}
  • Related