Hello,
I don't have much experience using the math functions within PowerApps. Looking for some guidance here.
Scenario:
Questions:
Specifics:
Thanks for the insights!
Solved! Go to Solution.
Or this if you want it to dynamically adjust to the image size and placement.
UpdateContext({randomX:Round((Rand()*imgMap.Width),0)+imgMap.X})
UpdateContext({random:Round((Rand()*imgMap.Height),0)+imgMap.Y})
Sweet! Thanks for the guidance @Pstork1.
Heres what I finally went with:
Set(varRandX, (Rand() * (imgMap.Width - icnMapPin.Width)) + imgMap.X); Set(varRandY, (Rand() * (imgMap.Height - icnMapPin.Height)) + imgMap.Y)
Key was subtracting the MapPin.Width and .Height from the map to create a "buffer" for the pin itself.
Hm... Thought this would work, but nope:
Set(varRandX, Rand() * (1330 - 336)); Set(varRandY, Rand() * (850 - 140))
Since this appears to be for some kind of a demo. Have you considered making a collection of location coordinates that map to locations on your map and then using Rand() to pick the index of one of those?
UpdateContext({random:Round((Rand()*25),0)})
Hi @Pstork1 ,
Thanks for the reply. This would be a good solution if I was calling an API and bringing back a map with actual coordinates. As you said, I'm demoing and just need to make the Map Pin randomly stay within the bounds of the map image.
Just tried this to no avail:
Set(varRandX, Rand() * (imgMap.Width + imgMap.X)); Set(varRandY, Rand() * (imgMap.Height - imgMap.Y))
This won't keep it from showing up in inappropriate places on the map. But if you just want to make sure its inside the boundaries try this:
UpdateContext({randomX:Round((Rand()*1000),0)+300})
UpdateContext({random:Round((Rand()*550),0)+120})
Or this if you want it to dynamically adjust to the image size and placement.
UpdateContext({randomX:Round((Rand()*imgMap.Width),0)+imgMap.X})
UpdateContext({random:Round((Rand()*imgMap.Height),0)+imgMap.Y})
Sweet! Thanks for the guidance @Pstork1.
Heres what I finally went with:
Set(varRandX, (Rand() * (imgMap.Width - icnMapPin.Width)) + imgMap.X); Set(varRandY, (Rand() * (imgMap.Height - icnMapPin.Height)) + imgMap.Y)
Key was subtracting the MapPin.Width and .Height from the map to create a "buffer" for the pin itself.
I didn't think about that. Good catch,
Power Apps User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.
Did you miss the call?? Check out the Power Apps Community Call here!
User | Count |
---|---|
265 | |
209 | |
77 | |
41 | |
33 |
User | Count |
---|---|
344 | |
217 | |
117 | |
71 | |
54 |