harmonyos轻量地图sdk初始化
sdkinitializer.initialize(this,"your api_key");
publicclassshowmapabilityextendsability{/*** 布局*/privatepositionlayout rootlayout;/*** mapview*/privatemapview mmapview;/*** mapview控制器*/privatebaidumap mbaidumap;@overridepublicvoidonstart(intent intent){super.onstart(intent);// 布局initpositionlayout();addmapview();super.setuicontent(this.rootlayout);}@overridepublicvoidonactive(){super.onactive();}@overridepublicvoidonforeground(intent intent){super.onforeground(intent);}@overrideprotectedvoidonstop(){super.onstop();mmapview.ondestroy();}privatevoidinitpositionlayout(){this.rootlayout=newpositionlayout(this);this.rootlayout.setcontentposition(0,0);this.rootlayout.setwidth(componentcontainer.layoutconfig.match_parent);this.rootlayout.setheight(componentcontainer.layoutconfig.match_parent);// 背景色shapeelement shapeelement =newshapeelement();shapeelement.setshape(shapeelement.alpha_min);shapeelement.setrgbcolor(newrgbcolor(255,255,255));this.rootlayout.setbackground(shapeelement);}privatevoidaddmapview(){// 创建mapviewmmapview =newmapview(getcontext());mmapview.setposition(0,0);mmapview.setwidth(componentcontainer.layoutconfig.match_parent);mmapview.setheight(componentcontainer.layoutconfig.match_parent);this.rootlayout.addcomponent(mmapview);mbaidumap = mmapview.getmap();}}
运行效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?