0

I have requirement where I want to calculate Bounding box for given latitude and longitude and Distance.

Distance can be in Miles, meters and feet as well.

I have found many article on how to calculate Bounding Box in KM but not for Miles, meters and Feet. Could anyone help me in how to calculate in Miles, meters and Feet.

This thread has information in KM How to calculate the bounding box for a given lat/lng location?

either Javascript or C# code is fine as well.

Looking for simpler formula because we will be implementing this in PowerApps.

Any Help would be much appreciated.

User
  • 31
  • 5

1 Answers1

1

You can implement that complex formula in Power Apps as well - see the example below which is a translation of the first answer to your linked post. This assumes that the values for the latitude, longitude and half length in kilometers are in text input controls named txtLat, txtLong, txtHalfSideKm, respectively.

Set(
    bounds,
    With(
        {
            WGS84_a: 6378137.0, // Major semiaxis [m]
            WGS84_b: 6356752.3, // Minor semiaxis [m]
            lat: Radians(Value(txtLat.Text)), lon: Radians(Value(txtLon.Text)),
            halfSideMeters: Value(txtHalfSideKm.Text) * 1000
        },
        With(
            {
                An: WGS84_a * WGS84_a * Cos(lat), Bn: WGS84_b * WGS84_b * Sin(lat),
                Ad: WGS84_a * Cos(lat), Bd: WGS84_b * Sin(lat)
            },
            With(
                { Radius: Sqrt( (An*An + Bn*Bn) / (Ad*Ad + Bd*Bd) ) },
                With(
                    { pRadius: Radius * Cos(lat) },
                    {
                        latMin: Degrees(lat - halfSideMeters / Radius),
                        latMax: Degrees(lat + halfSideMeters / Radius),
                        lonMin: Degrees(lon - halfSideMeters / pRadius),
                        lonMax: Degrees(lon + halfSideMeters / pRadius)
                    }
                )
            )
        )
    )
)

If you want the half-side in other units, the only place you'll need to change would be the definition of the halfSideMeters - you'll need to use the appropriate conversion.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • Thanks for Reply, Problem is we do not know the appropriate bounding box conversion for feet and others. What will be the values for these WGS84_a: 6378137.0, WGS84_b: 6356752.3. Could you please elaborate. – User Mar 16 '21 at 13:48
  • These are the values in meters; the bounding box is given in lat/lon coordinates; if you want to specify the halfSide distance in feet, then you need to convert that to meters (in the example above the distance is given in Km, and to convert to meters we multiply by 1000; if you have it in feet, you would divide it by 0.3044 or something similar) – carlosfigueira Mar 16 '21 at 14:51