web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Detected location on map
Power Apps
Answered

Detected location on map

(1) ShareShare
ReportReport
Posted on by 31

Hi All,

 

I am newbie on the developing Power Apps and I am sticking frequently. I am trying to create travel safety app like below.

Fatih_0-1699103715573.png

 

I want to show the user detected location on the map located right side to ensure they know their detected location before report it. How can I determine current location. So this can be used on computer or mobile.

 

Once, I show the detected location, I want to record this detected location, full name, label name (green and red buttons), and detected time and date when they clink these red or green buttons.

 

How can I do this? When we talk about the emergency time is important so I am trying to collect as much as data without inputting it.

 

Thanks in advance for your supports.

 

 

 

Categories:
  • Fatih Profile Picture
    31 on at

    Any idea?

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    HI @Fatih 

    Try This 

    set the MapControl.Latitude and MapControl.Longitude properties

     

    MapControl.Latitude = Location.Latitude;
    MapControl.Longitude = Location.Longitude;

     

    Write this code on select property of your buttons i am write the code for green button

     

    Patch(
     YourDataSource, // Replace with your actual data source name
     Defaults(YourDataSource),
     {
     DetectedLocation: Location.Latitude & ", " & Location.Longitude,
     FullName: User().FullName, // Assuming you want to capture the name of the logged-in user
     LabelName: "Green", // This is the label for the button
     DetectedTime: Now() // Captures the current time and date
     }
    );

     

    Please accept this solution if it resolves the issue. ✅
    Best regards,
    Muhammad Ali

  • Fatih Profile Picture
    31 on at

    Hi @M_Ali_SZ365 

     

    Thank you for your reply.

     

    I selected the Map on the right side, and added following information to show detected location and it worked fine.

    In Advanced Properties

    DefaultLatitude
    Location.Latitude
    
    CurrentLocationLatitude
    Location.Latitude
    
    DefaultLongitude
    Location.Longitude
    
    CurrentLocationLongitude
    Location.Longitude

    I updated the patch code as below. However, I couldn't be successful and it hasn't worked.

    Patch(
     'Travel Safety Tracker', // Replace with your actual data source name
     Defaults('Travel Safety Tracker'),
     {
     DetectedLocation: Location.Latitude & ", " & Location.Longitude,
     FullName: User().FullName, // Assuming you want to capture the name of the logged-in user
     LabelName: "I AM SAFE", // This is the label for the button
     DetectedTime: Now() // Captures the current time and date
     }
    );

    In addition, when we click on the button, I could not figure out which list columns the collected data will be saved in. Is there an addressing required for this? Save the name in column A, save the date in column B, etc.

    I left the columns in my list below. Sorry if I'm taking your time with silly questions, but I'm a novice in these matters.

     

    Fatih_0-1699281097942.png

     

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    Hello there!

    Great to hear you've made progress with displaying the user's location on the map. For recording the data when a user clicks on the "I AM SAFE" or "I NEED HELP" buttons, we'll use a simple function in Power Apps called Patch to update your 'Travel Safety Tracker' list.

    Here's what you need to do:

    1. Make sure each button (Green and Red) is set up to capture the right status. When you write the Patch function, you'll include "I AM SAFE" for the green button and "I NEED HELP" for the red button, just like this:
    // For the green button
    Patch(
     'Travel Safety Tracker',
     Defaults('Travel Safety Tracker'),
     {
     FullName: User().FullName,
     Status: "I AM SAFE",
     DateAndTime: Now(),
     Latitude: Location.Latitude,
     Longitude: Location.Longitude
     }
    );
    
    // And a similar one for the red button with "I NEED HELP" as the status.

     

    1. Next, you'll want to ensure that these pieces of information match the columns in your list. For instance, FullName should go into the "Full Name" column, Status should match "Status," DateAndTime aligns with "Date and Time," and so forth.
    2. There's no need to specify column A, B, etc., because Power Apps does that for you as long as the names in your Patch function match the column names in your list.
    3. If you hit a snag, make sure the names used in the Patch function exactly match the column names in your 'Travel Safety Tracker' list. This is crucial for the data to go into the right place.

    Please accept this solution if it resolves the issue. ✅
    Best regards,
    Muhammad Ali

  • Fatih Profile Picture
    31 on at

    Hi @M_Ali_SZ365 

     

    I couldn't do it again. Here is the last code just for the green button.

    Patch(
     'Travel Safety Tracker',
     Defaults('Travel Safety Tracker'),
     {
     FullName: FullName,
     Status: "I AM SAFE",
     DateandTime: Now(),
     ReportedLocation: Location.Latitude,
     Longitude: Location.Longitude,
     }
    );

    FullName: FullName,
    Status: "I AM SAFE",
    DateandTime: Now(),
    ReportedLocation: Location.Latitude,
    Longitude: Location.Longitude,

     

    All these are matching with my column id in the list.

    Fatih_0-1699283789168.png

     

    I tried button id and button text both but I am receiving an error.

    Fatih_1-1699283848991.png

     

     

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    @Fatih 

    To display the user's current location on the map:

    1. Set the map control's properties to use the device's location.
      • For DefaultLatitude, use Location.Latitude
      • For DefaultLongitude, use Location.Longitude

    For recording the data when a user clicks on the "I AM SAFE" or "I NEED HELP" button:

    1. Use the Patch function to send the data to your list or table.

    Here's what the function would look like for the "I AM SAFE" button:

     

    Patch(
     'Travel Safety Tracker', // Your actual data source name
     Defaults('Travel Safety Tracker'), // Creates a new record
     {
     DetectedLocation: Location.Latitude & ", " & Location.Longitude,
     FullName: User().FullName, // Captures the name of the logged-in user
     LabelName: "I AM SAFE", // Indicates the button pressed
     DetectedTime: Now() // Captures the current time and date
     }
    );

     

    Make sure to replace 'Travel Safety Tracker' with the actual name of your data source. Place this code in the OnSelect property of the "I AM SAFE" button.

    Repeat a similar process for the "I NEED HELP" button, changing the LabelName to "I NEED HELP".

    If the Patch function isn’t working:

    • Double-check the names of the fields in your data source match the keys in your Patch function.
    • Ensure you have the necessary permissions to write to the data source.
    • Confirm that the data types for each field match the data you're sending from the app.
  • Fatih Profile Picture
    31 on at

    Hi @M_Ali_SZ365 

     

    Thanks for your patience while supporting me. I am not still successful.

    Fatih_0-1699310685410.png

     

    I tried different variations but still same. Above is the message from help section and below is the code I am using. I checked several time and columns are matching with this code.

     

    Patch(
     'Travel Safety Tracker', // Your actual data source name
     Defaults('Travel Safety Tracker'), // Creates a new record
     {
     FullName: User().FullName, // Captures the name of the logged-in user
     Status: "I AM SAFE", // Indicates the button pressed
     DateandTime: Now(), // Captures the current time and date
     ReportedLocation: Location.Latitude & ", " & Location.Longitude
     }
    );

     

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    @Fatih 

    It looks like there's a bit of a mix-up with the type of info your app is expecting for the 'FullName' field. Here’s what you can do to fix it:

    1. Check Your Data Source: Make sure the 'FullName' column in your 'Travel Safety Tracker' list or table is set to take text.

    2. Test the Output: Put User().FullName in a text label within your app. If it doesn't show your name, there's a problem with how the app gets your name.

    3. Try a Dummy Text: Temporarily replace User().FullName with a plain text like "John Doe" in your code. If it works, then the issue is with User().FullName.

    Try This Code

     

    Patch(
     'Travel Safety Tracker',
     Defaults('Travel Safety Tracker'),
     {
     FullName: "John Doe", // Replace with your name
     Status: "I AM SAFE",
     DateandTime: Now(),
     ReportedLocation: Location.Latitude & ", " & Location.Longitude
     }
    );

     

    Please accept this solution if it resolves the issue. ✅
    Best regards,
    Muhammad Ali

  • Fatih Profile Picture
    31 on at

    Hi @M_Ali_SZ365 

     

    1. Check Your Data Source: I added my list column types below. FullName column type is person. So I created one more column, name is Surveyor with text type. And the form still not recorded.

    2. Test the Output: I added a label with given code. My name is shown properly on the label. so User().FullName is working fine.

    3. Try a Dummy Text: I tried this as well. It doesn't work.

     

    I don't know what I am doing wrong.

     

    Fatih_0-1699367090210.png

     

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    @Fatih 

     

    Kindly Change the Full Name Columns Type person and group to single line of Text and then test this code

    Patch(
     'Travel Safety Tracker', // Your actual data source name
     Defaults('Travel Safety Tracker'), // Creates a new record
     {
     FullName: User().FullName, // Captures the name of the logged-in user
     Status: "I AM SAFE", // Indicates the button pressed
     DateandTime: Now(), // Captures the current time and date
     ReportedLocation: Location.Latitude & ", " & Location.Longitude
     }
    );

     Please accept this solution if it resolves the issue. ✅
    Best regards,
    Muhammad Ali

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 339 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 289

#3
Mohsin Ali Profile Picture

Mohsin Ali 228

Last 30 days Overall leaderboard