sharepointmapslatitude-longitudebing-mapspowerapps

can we control the format of the Latitude and Longitude generated by power apps


I have a button to send the user location by clicking on a button inside our canvas app and store the location inside SharePoint:-

Patch(
'Technicians Locations',
Defaults('Technicians Locations'),
{
Longitude: Location.Longitude,
Latitude: Location.Latitude

});

now the generated location will have this format, for example:-

Longitude:- 31.523026

Latitude:- 35.531207

while inside our ERP system the Longitude and Latitude, will have a format as follow, where they contain these 2 characters (° and '), as follow:-

Longitude:-32°1'7.93

Latitude:- 35°51'53.93

where I am calculating the distance between the user location and the asset location using BingMAP API:-

Distance: BingMaps.GetRouteV2(
                    (relatedAsset.Latitude & ", " & relatedAsset.Longitude),
                    (user.Latitude & ", " & user.Longitude)
                ).travelDistance

but since i have different formats for the user location and asset location this is not working. so can I control the format of the user location that power apps generate? or convert the asset location to have similar format as the one generated by power apps? so the distance calculation will work?

Thanks


Solution

  • In order for your coordinates as they are in your ERP system, they would need to be a string rather than a number, thus you not only have a formatting issue, but a type issue. The Bing Maps developer API's do have conversions for degrees minute second (DMS) coordinates in the web SDK, but I don't think it is exposed through the power apps platform. The following is an example Excel formula for converting DMS coordinates:

    =TEXTBEFORE(A2, "°")+TEXTBEFORE(TEXTAFTER(A2, "°"), "'")/60+TEXTBEFORE(TEXTAFTER(A2,"'"),"""")/3600
    

    You can find a blog post on this here: https://www.statology.org/excel-convert-degrees-minutes-seconds-to-decimal-degrees/