中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
地图选点Button的实现
微信扫码分享
// ChooseLocation.ets import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { build() { Row() { Column() { // 声明FunctionalButton FunctionalButton({ params: { // OpenType.CHOOSE_LOCATION表示Button为地图选点类型 openType: functionalButtonComponentManager.OpenType.CHOOSE_LOCATION, label: '地图选点', // 调整Button样式 styleOption: { bgColor: functionalButtonComponentManager.ColorType.DEFAULT, size: functionalButtonComponentManager.SizeType.DEFAULT, plain: false, disabled: false, loading: false, hoverClass: functionalButtonComponentManager.HoverClassType.HOVER_CLASS, hoverStartTime: 0, hoverStayTime: 0, styleConfig: new functionalButtonComponentManager.ButtonConfig() .fontSize(20) .fontColor(Color.Black) } }, // OpenType为“CHOOSE_LOCATION”时,回调必须选择“onChooseLocation” controller: new functionalButtonComponentManager.FunctionalButtonController() .onChooseLocation((err, data) => { if (err) { // 错误日志处理 hilog.error(0x0000, "testTag", "error: %{public}d %{public}s", err.code, err.message); return; } // 成功日志处理 hilog.info(0x0000, "testTag", "succeeded in choosing location"); let name: string = data.name; let address: string = data.address; let longitude: number = data.longitude; let latitude: number = data.latitude; }) }) } .width('100%') } .height('100%') } }