鸿蒙服务卡片,api使用js开发

在鸿蒙里面使用api8的js开发服务卡片,有没有例子?如何进行数据交换?

  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/222005
  • 这篇博客你也可以参考下:API接口获得数据后处理JS数组(包含字符串对象)分组、过滤和筛选的解决方案
  • 除此之外, 这篇博客: 图文并茂--微信小程序,获取用户地理位置信息,并调用腾讯地图API来获取用户具体位置中的 js 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • data: {
        myLocation: 'GET LOCATION',
          },
    openMap() {
        var myThis = this
        wx.getLocation({
          type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
          success: function (res) {
            // success
            console.log('获取位置2');
            myThis.setData({
              myLocation: JSON.stringify(res)
            })
            console.log(res.latitude);
            console.log(res.longitude);
    
            wx.openLocation({
              latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬
              longitude: res.longitude, // 经度,范围为-180~180,负数表示西经
              scale: 28, // 缩放比例
              name: "要找的地方名字(某某饭店)",
              address: "地址:要去的地点详细描述"
            })
          }
        })
      },
    openMap1() {
        var myThis = this
        wx.getLocation({
          type: 'wgs84',
          success(res) {
            // 纬度,范围为 -90~90,负数表示南纬
            const latitude = res.latitude
            // 经度,范围为 -180~180,负数表示西经	
            const longitude = res.longitude
            // 速度,单位 m/s	
            const speed = res.speed
            // 位置的精确度,反应与真实位置之间的接近程度,可以理解成10即与真实位置相差10m,越小越精确
            const accuracy = res.accuracy
            myThis.setData({
              myLocation: '当前经度:' + latitude + '\n' + '当前纬度:' + longitude + '\n' + '当前速度:' + speed + '\n' + '当前位置精确度:' + accuracy
            })
            console.log(res.latitude);
            console.log(res.longitude);
          }
        })
      },