cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Pass Location Info to Flow

Team,

I've done a bit of searching and can't find anything overtly relevant, but I'm new...so apologies if this is covered somewhere.

 

I'm looking to create a PowerApp with just a single button.   When the user presses it, the location information is captured from the mobile device and passed to a Flow.

 

I've tried simple stuff (I'm not into code at all) like using UpdateContext on the OnSelect to set lat: Location.Latitude and so on, but that doesn't show as a dynamic value in Flow for me to use in the action.

 

Is this possible?  Seems like it would be.

Thanks for the help

1 ACCEPTED SOLUTION

Accepted Solutions
SanAndresMan1
Level: Powered On

Re: Pass Location Info to Flow

This should be fairly straight forward:

 

1. I have added 2 labels, one called txtLatitude and made that Location.Latitude; and one called txtLongitude and made that Location.Longitude - NOTE: just did this so you can see the location of the device, but this is not necessary as you can pass in Location.Latitude and Location.Longitude directly to the flow.

 

2. I then created a flow called Location Flow, and use PowerApps as the trigger. I then added 2 steps, each with an Initialize Variable, and in both cases I asked it to Ask in PowerApps, both variables of type Float.

 

3. I added an additional step to the flow to send me an email with the coordinates, just to test it was working

 

4. I went back to PowerApps and added a Submit button, then pointed to Action | Flows for this button and selected the Flow I just created. I then pointed the LocationFlow.Run() parameters to txtLatitude and txtLongitude. 

 

I was able to successfully run the app and the flow. Please let me know if you have any questions

View solution in original post

11 REPLIES 11
PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Pass Location Info to Flow

You've got the right idea to use UpdateContext or Set to get the location:

 

Set(variable,Location)

Each time you click it, the variable will change to the current location.

You can also set a label to show the Location.Latitude and Location.Longitude.

 

But I'm unclear why you need to do this in PowerApps. If all you need is a button, you could create a Flow button that gets the location if you're going to use a flow anyway. Lat and long are dynamic content that you can select for future actions if you start with a Flow button.

 

image.png

 

Super User
Super User

Re: Pass Location Info to Flow

@Mr-Dang-MSFT - 

Thanks for the response.  I did consider just a Flow button (would be a ton easier for me) but there are two main reasons for using PowerApps - 

First - I am using the location to feed an HTTP GET thing, which will return some JSON results that I'd like to present in a gallery.  To do this in Flow, I think I am limited to something like an HTML email or adaptive cards (blog on that coming soon), which was not the experience I was going for in this project.

 

Second - I want/need to teach myself practical Power Apps.  I've done the App in a day and done some connecting to data, but I get flummoxed quickly because I don't code.  I think there is an audience of similar folks looking to expand their knowledge and usefulness, but maybe not wanting the deep rabbit hole that is programming/code.  My intent is to go from zero to one and help others do the same.

 

Back to the original query, though, once I set the variable in PowerApps, does that create a dynamic value for me to use in subsequent Flow actions?  I can't seem to get that part to work.

 

Thanks again for the help.

 

-Ed-

PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Pass Location Info to Flow

Clicking the button to get the location gets you a static value of where you are in that moment. The variable does not change until you click the button again.

 

There's a few ways to do what you want to achieve.

  1. Multiple actions can be done with the click of a button by chaining them with a semi-colon. In your case, you'll want to figure out the current lcoation before running your flow.

    Set(varLocation,Location);
    
    FlowName.Run(Text(varLocation.Latitude),Text(varLocation.Longitude))
    The semicolon makes the actions go in order. The second action will not proceed until the first one completes.
  2. You can skip the variable altogether and feed the location directly in the Flow statement:
    FlowName.Run(Text(Location.Latitude),Text(Location.Longitude))

Note that in both cases, I wrapped Text around the location. I assume whatever you're using is going to consume them as text. Remove Text() if you want it as a number.

 

Also note that I'm assuming your flow has 2 parameters, the first asking for lat, the second for long. Move things around as needed.

 

 

SanAndresMan1
Level: Powered On

Re: Pass Location Info to Flow

This should be fairly straight forward:

 

1. I have added 2 labels, one called txtLatitude and made that Location.Latitude; and one called txtLongitude and made that Location.Longitude - NOTE: just did this so you can see the location of the device, but this is not necessary as you can pass in Location.Latitude and Location.Longitude directly to the flow.

 

2. I then created a flow called Location Flow, and use PowerApps as the trigger. I then added 2 steps, each with an Initialize Variable, and in both cases I asked it to Ask in PowerApps, both variables of type Float.

 

3. I added an additional step to the flow to send me an email with the coordinates, just to test it was working

 

4. I went back to PowerApps and added a Submit button, then pointed to Action | Flows for this button and selected the Flow I just created. I then pointed the LocationFlow.Run() parameters to txtLatitude and txtLongitude. 

 

I was able to successfully run the app and the flow. Please let me know if you have any questions

View solution in original post

Super User
Super User

Re: Pass Location Info to Flow

Thank you both for the help.  I'll hit them both in order and let you know what I found:

 

For Brian's ( @Mr-Dang-MSFT  ) - I get a couple of errors in PowerApps.  The first is "Invalid number of arguments: received 2, expected 1".  So I change the OnSelect formula to FlowName.Run(Text(Location.Latitude)) (thinking that I'd get rid of one of the arguments) and now I get: Invalid argument type (Text). Expecting a Record value instead. AND The function 'Run' has some invalid arguments.  I did change "FlowName" to match my Flow.

 

For @SanAndresMan1  - When you say "I then pointed the LocationFlow.Run() parameters to txtLatitude and txtLongitude.", do you mean the formula actually looks like "Flowname.Run(txtLatitude, txtLongitude)"?  Because that generates the 'number of arguments' error listed above.

 

Thanks again to both of you for the help.

-Ed-

SanAndresMan1
Level: Powered On

Re: Pass Location Info to Flow

Ed,

Yes, I did get the invalid number of arguments error on a set variable operation, which I never introduced to begin with. I believe this is a flow bug. All I did was I passed in a value of 1.

LocationFlow.Run(1, txtLatitude, txtLongitude)
Super User
Super User

Re: Pass Location Info to Flow

I'm getting the error from within PowerApps, and I don't think it's running the Flow with the error.

 

I pretty much copied and pasted what you have and am still getting the error.  If I try to run the app with the error, the Flow never triggers.

SanAndresMan1
Level: Powered On

Re: Pass Location Info to Flow

Ed,

Check your Twitter inbox

PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Pass Location Info to Flow

Any time that you are creating a flow that is triggered by PowerApps, you need to tell the Flow what you are going to feed it from PowerApps.image.png

 

In Flow, you'll see 'Ask in PowerApps' appear as an option for Dynamic Content. If it doesn't, click 'See More.'

image.png

 

Above, I have 8 things that I want PowerApps to tell the flow so it can do a Bing image search; these are its parameters. 

 

Every API is different and requires different type of data. So earlier I gave an example of sending latitude and longitude as two separate parameters--that would only work if in the flow, you had clicked 'Ask in PowerApps' in two places. You'll need to adjust it to fit whatever setup you have in your flow.

 

You'll need to go into the API reference for the call you want to make to see exactly what information you want to feed it and in what way. It's really just about sending the right data types at this point.

 

@SanAndresMan1 @seadude @ThatAPIGuy 

I know @seadude has specifically used lat longs in his flows and custom connectors.

@ThatAPIGuy has a youtube example using HTTP + PowerApps + Flow.

 

And here's an example using lat longs in a hiking app with app and flow included: 

https://aka.ms/hiking/package

You can import it at web.powerapps.com -> Apps -> Import -> Upload the zip file.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,670)