Home > Web Front-end > JS Tutorial > WeChat enterprise account development WeChat attendance Baidu map positioning_javascript skills

WeChat enterprise account development WeChat attendance Baidu map positioning_javascript skills

WBOY
Release: 2016-05-16 15:39:51
Original
3263 people have browsed it

Previously, in the development of WeChat Enterprise Account: WeChat Attendance, I used the positioning component of Baidu Map, but found that a positioning failure prompt appeared on some mobile phones, so I studied Baidu Map. The original web component Baidu was not planning to update, so I re-checked other APIs of Baidu Maps, and there is also a JavaScript API public version, so I tried it, but unexpectedly it was solved.

The core code is very simple:

<div id="allmap"></div> 
 <script type="text/javascript" src="http://api.map.baidu.com/api&#63;v=2.0&ak=kkkk"></script> 
 <script type="text/javascript"> 
 // 百度地图API功能 
 var map = new BMap.Map("allmap"); 
 var circle = new BMap.Geolocation(); 
 circle.getCurrentPosition(locationResult); // 
 map.addOverlay(circle); 
 function locationResult(geolocationResult) { 
  var Status = this.getStatus() 
  if (Status == 0)//检索成功。对应数值“0”。 
  { 
   $("#lng").val(geolocationResult.point.lng); 
   $("#lat").val(geolocationResult.point.lat); 
   var address = geolocationResult.address; 
   $("#city").val(address.city); 
   $("#district").val(address.district); 
   $("#street").val(address.street); 
   $("#address").val(address.province + address.city + address.district + address.street + address.street_number); 
  } 
  else { 
   alert("定位失败错误码" + Status) 
  } 
 } 
</script> 
Copy after login

Achieve results


The above content is to share with you the WeChat attendance and Baidu map positioning developed by WeChat enterprise public account. The code is simple and easy to understand. Friends who need it, come and learn it.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template