You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Apps经纬度格式控制与ERP格式转换适配Bing Maps API

解决方案

一、转换ERP度分秒经纬度为十进制(推荐)

Bing Maps API的GetRouteV2接口仅支持十进制格式的经纬度参数,所以将ERP返回的度分秒格式转成十进制是最直接的解决方式。

转换逻辑

度分秒转十进制的公式为:
十进制值 = 度 + 分/60 + 秒/3600
注意保留原始的正负符号(比如西经、南纬为负)。

集成到距离计算代码中

直接在Bing Maps调用里加入转换逻辑,修改后的代码如下:

Distance: BingMaps.GetRouteV2(
    // 转换ERP资产的度分秒经纬度为十进制
    With(
        {
            // 处理纬度
            latRaw: Trim(relatedAsset.Latitude),
            latIsNegative: Left(latRaw, 1) = "-",
            latCleanText: If(latIsNegative, Right(latRaw, Len(latRaw)-1), latRaw),
            // 处理经度
            lonRaw: Trim(relatedAsset.Longitude),
            lonIsNegative: Left(lonRaw, 1) = "-",
            lonCleanText: If(lonIsNegative, Right(lonRaw, Len(lonRaw)-1), lonRaw)
        },
        With(
            {
                // 拆分纬度的度、分、秒
                latDegree: Value(First(Split(latCleanText, "°")).Result),
                latMinute: Value(First(Split(Last(Split(latCleanText, "°")).Result, "'")).Result),
                latSecond: Value(Last(Split(Last(Split(latCleanText, "°")).Result, "'")).Result),
                // 拆分经度的度、分、秒
                lonDegree: Value(First(Split(lonCleanText, "°")).Result),
                lonMinute: Value(First(Split(Last(Split(lonCleanText, "°")).Result, "'")).Result),
                lonSecond: Value(Last(Split(Last(Split(lonCleanText, "°")).Result, "'")).Result)
            },
            // 拼接成十进制格式的经纬度字符串
            $"{If(latIsNegative, -(latDegree + latMinute/60 + latSecond/3600), latDegree + latMinute/60 + latSecond/3600)}, {If(lonIsNegative, -(lonDegree + lonMinute/60 + lonSecond/3600), lonDegree + lonMinute/60 + lonSecond/3600)}"
        )
    ),
    // 用户位置本身是十进制,直接拼接
    $"{user.Latitude}, {user.Longitude}"
).travelDistance

二、将Power Apps生成的十进制转成度分秒存储(不推荐)

如果需要让SharePoint里存储的用户位置和ERP格式统一,可以在Patch时先把十进制转成度分秒格式,但后续调用Bing Maps仍需转回十进制,多了额外步骤,仅作参考。

转换逻辑

十进制转度分秒的步骤:

  1. 取绝对值,分离出度(整数部分)
  2. 剩余小数部分乘以60,分离出分(整数部分)
  3. 剩余小数部分再乘以60,得到秒(保留两位小数)
  4. 保留原始正负符号

修改后的Patch代码

Patch(
    'Technicians Locations',
    Defaults('Technicians Locations'),
    {
        Longitude: With(
            {
                decValue: Location.Longitude,
                absValue: Abs(Location.Longitude),
                degree: Int(absValue),
                remaining: absValue - degree,
                minute: Int(remaining * 60),
                second: Round((remaining * 60 - minute) * 60, 2)
            },
            $"{If(decValue < 0, "-", "")}{degree}°{minute}'{second}"
        ),
        Latitude: With(
            {
                decValue: Location.Latitude,
                absValue: Abs(Location.Latitude),
                degree: Int(absValue),
                remaining: absValue - degree,
                minute: Int(remaining * 60),
                second: Round((remaining * 60 - minute) * 60, 2)
            },
            $"{If(decValue < 0, "-", "")}{degree}°{minute}'{second}"
        )
    }
);

内容的提问来源于stack exchange,提问作者microsoftdeveloperdesigner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 17:40:32