How can i Show Current Location in Website

2
I am new to mendix Platform , i want to show current location in my application , kindly give some instruction or guideline for (How can i do it).
asked
2 answers
2

Hi Surya,

 

You probably want the location of the user in the browser. This can be achieved with the HTML Geolocation API.

https://www.w3schools.com/html/html5_geolocation.asp

 

var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
}

 

To include this in Mendix, you need to add a button to your page.

Set as onclick action a Nanoflow.

This nanoflow can trigger an JavaScript Action.

In this Javascript Action, you can use the Javascript snippet as shown above.

answered
2

Take a look at the Nanoflow Commons module (available in the Marketplace if it’s not already in your project).

This provides the GetCurrentLocation action which can return the device’s current location in an Entity you can use from a nanoflow. 

https://docs.mendix.com/appstore/modules/nanoflow-commons/

I hope this helps.

answered