Baidu Map plug-in development using three and jquery function (a.b) sorting, etc.

Source: Internet
Author: User
Tags sin

Load Store function querystorelist (ID) {showload ();    var search = $ ("#search"). Val ();    var Cityid = $ ("#cityId"). Val ();    if (ID!=null && id! = ") {cityid=id;                            } $.ajax ({url:ctx+ "/weixin/store/querystorelist", data:{Wechatid: ${param.wechatid}, Search:search, Cityid:cityid}, Success:function (data) {Hidel            Oad ();                if (data! = null && data.length > 0) {var html = ""; $.each (Data,function (i,a) {//Calculate distance
//$.each (data,function (i,a) {"Data object can also be written in $ (data). each (function (i,a) {method body})"}) Loopvar distance=getflatterndistance (A.LATITUDE,A.LONGITUDE,NOWLAT,NOWLNG);
The//getflatterndistance function calculates the distance based on the latitude and longitude of two locationsdistance=distance.tofixed (0);//Preserve the number of digits after the decimal pointA.distance=distance; }) Data=data.sort (A, B) {//by distance from small to large sort
//data.sort (A, b) {"Data.sort (parameter sequence)" is a positive order by default})return a.distance-b.distance; }); $.each (Data,function (i,a) {html + = "<Divclass= ' List_ceClearfix '>";
//class= ' list_ce ' Clearfix ' class selector as a style selection, in the CSS of the two Gothic style has been defined, Clearfix has the effect of removing the buoy, to prevent the module displacement HTML + = "<ulclass= ' Clearfix '>"; HTML + = "<Liclass= ' One '><imgsrc= ' ${res}/upload/' +a.wechatid+ "/" +a.image+ "'></Li>"; HTML + = "<Liclass= ' Both '>"; var dis=number (a.distance); if (dis >1000) {dis=dis/1000 dis=dis+ "km"; }else{dis=dis+ "M"; } HTML + = "<H2>"+a.name+ dis+"<span><ahref= ' Tel: ' +a.phone+ '><img
src= ' ${res}/template/002/images/m2.png '></a></span></H2>"; HTML + = "<Pclass= ' Fonts '>Address: "+a.address+"</P>"; HTML + = "<Pclass= ' ft '>Phone:<ahref= ' Tel: ' +a.phone+ '>"+a.phone+"</a></P>"; HTML + = "</Li>"; HTML + = "<Liclass= ' tre '>"; HTML + = "<Ponclick= ' Gogps ("+a.id+") '><imgsrc= ' ${res}/template/002/images/m1.png '></P>"; HTML + = "</Li>"; HTML + = "</ul>"; HTML + = "</Div>"; HTML + = "<Divclass= ' Bres '></Div>"; }) $ ("#menuList"). Empty (). append (HTML);
//Empty and re-assign value } else{}})}

Function:

getflatterndistance get distance based on latitude and longitude of two locations

Calculates the distance function getflatterndistance (lat1,lng1,lat2,lng2) {    var f = Getrad (parsefloat (LAT1 + lat2)/2) based on the two latitude and longitude degrees;    var g = Getrad (parsefloat (LAT1-LAT2)/2);    var L = Getrad (parsefloat (lng1-lng2)/2);    var sg = Math.sin (g);    var sl = Math.sin (l);    var sf = Math.sin (f);    var s,c,w,r,d,h1,h2;    var a = Earth_radius;    var fl = 1/298.257;    sg = SG*SG;    SL = SL*SL;    SF = SF*SF;    s = sg* (1-SL) + (1-SF) *sl;    c = (1-SG) * (1-SL) + sf*sl;    W = Math.atan (math.sqrt (s/c));    R = math.sqrt (s*c)/w;    d = 2*w*a;    H1 = (3*r-1)/2/c;    H2 = (3*r + 1)/2/s;    return d* (1 + fl* (h1*sf* (1-SG)-h2* (1-SF) *SG));}






Baidu Map plug-in development using three and jquery function (a.b) sorting, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.