Acquiring positional information: latitude and longitude obtained by the first micro-channel public number, and then exchange latitude and longitude position
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script> <script> var signature = '@ViewBag.signature'; //微信 wx.config({ debug: false, appId: '211', timestamp:12 , nonceStr: ' 121 ' , Signature: Signature, jsApiList: [ ' getLocation ' ] }); wx.ready ( function () { wx.getLocation ({ Success: function (RES) { var Latitude = res.latitude; // latitude , floating-point, in the range of -90 ~ 90 var longitude = res.longitude; // longitude, floating-point, in the range of -180 ~ 180 [. var speed = res.speed; // speed, in meters / second meter var Accuracy = res.accuracy; // positional accuracy getAddress (Latitude, longitude); }, Cancel: function (RES) { Alert ( ' users are denied authorization obtain the geographic location ' ); }, Fail: function (RES) { Alert ( " Get location of the failure " ); } }); }); function getAddress (Latitude, longitude) { var Map = new new BMap.Map ( " allmap "); var point = new BMap.Point(longitude, latitude); var gc = new BMap.Geocoder(); gc.getLocation(point, function (rs) { var addComp = rs.addressComponents; var mapAddress = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber; vm.address = mapAddress; }); }
Calculating the distance:
/ **
* distance between two points is calculated
* pt1 {lng: "12.34" , lat: "3423"} latitude and longitude of the first point
* pt2 {lng: "12.34" , lat: "3423"} second point the latitude and longitude
* * /
getDistance: function (PT1, PT2) {
var new new BMap.Map Map = ( "Container");
var = new new BMap.Point Point1 (pt1.lng, pt1.lat);
var = new new Point2 the BMap. Point (pt2.lng, pt2.lat);
var = Distance map.getDistance (Point1, Point2);
return Distance;
},