You can capture the browser-provided current latitude and longitude in a MDriven Web application by adding two correctly named string variables to a ViewModel.
Configure geolocation
MDriven recognizes the following ViewModel variable names for the HTML5 geolocation API. When the browser permits location access, it assigns the current location to these variables.
| ViewModel variable | Type | Value supplied by the browser |
|---|---|---|
vClientLatitude
|
String | The current latitude |
vClientLongitude
|
String | The current longitude |
- Open the ViewModel that needs the user's location.
- Add a variable named
vClientLatitudeand set its type to String. - Add a variable named
vClientLongitudeand set its type to String. - Keep the names exactly as shown, including capitalization.
- Run the application in a browser and allow the browser's location-permission request.
- Use the two variables in the ViewModel where your application needs the captured coordinates.
Example
A delivery ViewModel can contain vClientLatitude and vClientLongitude. When a user opens the application and permits location access, the browser writes the user's current coordinate values into those variables. Your ViewModel can then use the values as input for its delivery-location logic.
Permission behavior
Location access is controlled by the browser. The browser assigns values only when permission is granted. If the user does not permit access, do not assume that either variable contains a location; design the ViewModel flow to handle the absence of location data.
The two variable names provide the built-in geolocation convention described on this page. For custom device integration, capability checks, permission handling, or access to other browser and device features, use an EXT_Component with the JavaScript Navigator API. See Integrate Device Features in MDriven Apps Using the Navigator API.
Related client values
MDriven also recognizes vClientScreenWidth as a client-value naming convention. It is separate from geolocation.
