Rewrite the official JavaScript API example of Baidu coordinate conversion to the traditional form of callback function

Source: Internet
Author: User
Tags translate function

Before Rewriting:

The official example of the JavaScript API example for coordinate conversion in Baidu maps is as Follows:

varpoints = [NewBmap.point (116.3786889372559,39.90762965106183),              NewBmap.point (116.38632786853032,39.90795884517671),              NewBmap.point (116.39534009082035,39.907432133833574),              NewBmap.point (116.40624058825688,39.90789300648029),              NewBmap.point (116.41413701159672,39.90795884517671)];//Map InitializationvarBM =NewBmap.map ("allmap"); Bm.centerandzoom (NewBmap.point (116.378688937,39.9076296510), 15);//callback function after the coordinate conversion is completeTranslatecallback =function(data) {if(data.status = = 0) {     for(vari = 0; I < data.points.length; i++) {bm.addoverlay (NewBmap.marker (data.points[i]));    Bm.setcenter (data.points[i]); }}}settimeout (function(){    varConvertor =NewBmap.convertor (); Convertor.translate (points,1, 5, translatecallback)},1000);

After Rewriting:

Rewrite the above code as a traditional JavaScript callback function:

functionTranslate (points,callback) {varConvertor=NewBmap.convertor (); Convertor.translate (points,1, 5, Callback) translatecallback=function(data) {if(data.status = = 0) {      varres=[];//Res is used to store the converted points array       for(vari = 0; I < data.points.length; i++) {bm.addoverlay (NewBmap.marker (data.points[i]));      Res.push (data.points[i]); } Callback (res) }}}//call the Translate function again,Translate (points,function(data) {console.log (data);//data is the converted points array})

After rewriting the Translate function accepts two parameters, the first parameter is the original Baidu points array, the second parameter passed in a callback Function.

Rewrite the official JavaScript API example of Baidu coordinate conversion to the traditional form of callback function

Related Article

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.