personalcancertoolkit / openmrs-module-patientportaltoolkit

Other
7 stars 9 forks source link

Make Near You grab the person's location & log Event for Near You and Zipcode #485

Open bmamlin opened 2 years ago

bmamlin commented 2 years ago

Fix the code for checking for the user's location so that it only occurs once. Users's should only see the location request once. Whether they accept or decline, it should not come up again.

bmamlin commented 2 years ago

Code of concern is here. Ideally, this code would be refactored to check for the user's location once (not track the user) using the HTML5 geolocation API, failing silently if the user's browser doesn't support the feature or if they have already denied sharing their location.

bmamlin commented 2 years ago

Simply commenting out the user_location_handler initialization might eliminate the popup (i.e., prevent location tracking).

Then replacing this line within the function assigned to get_position_from_userlocation_and_search to invoke the HTML5 geolocation API like this:

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    console.log("Geolocation is not supported by this browser.");
  }
}
bmamlin commented 2 years ago

When implemented properly, the only time the page should request the user's location is when/if the "Near you" button is clicked (which would invoke a getLocation() method like the one mentioned above). Navigating to the Communities tab should not request the user's location. Only when they click the "Near you" button would the browser fetch their location (if allowed) and update the Google map's focus.