diff --git a/scripts/langindex.json b/scripts/langindex.json
index dec428131..fc5464421 100644
--- a/scripts/langindex.json
+++ b/scripts/langindex.json
@@ -494,10 +494,12 @@
"addon.mod_data.expired": "data",
"addon.mod_data.fields": "data",
"addon.mod_data.foundrecords": "data",
+ "addon.mod_data.gettinglocation": "local_moodlemobileapp",
"addon.mod_data.latlongboth": "data",
"addon.mod_data.menuchoose": "data",
"addon.mod_data.modulenameplural": "data",
"addon.mod_data.more": "data",
+ "addon.mod_data.mylocation": "local_moodlemobileapp",
"addon.mod_data.nomatch": "data",
"addon.mod_data.norecords": "data",
"addon.mod_data.notapproved": "data",
diff --git a/src/addon/mod/data/fields/latlong/component/addon-mod-data-field-latlong.html b/src/addon/mod/data/fields/latlong/component/addon-mod-data-field-latlong.html
index c8acdf842..5b22625b9 100644
--- a/src/addon/mod/data/fields/latlong/component/addon-mod-data-field-latlong.html
+++ b/src/addon/mod/data/fields/latlong/component/addon-mod-data-field-latlong.html
@@ -10,6 +10,12 @@
°E
+
+
+
diff --git a/src/addon/mod/data/fields/latlong/component/latlong.ts b/src/addon/mod/data/fields/latlong/component/latlong.ts
index f005e95ee..767487e9d 100644
--- a/src/addon/mod/data/fields/latlong/component/latlong.ts
+++ b/src/addon/mod/data/fields/latlong/component/latlong.ts
@@ -14,7 +14,9 @@
import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Platform } from 'ionic-angular';
+import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation';
import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component';
+import { CoreDomUtilsProvider } from '@providers/utils/dom';
/**
* Component to render data latlong field.
@@ -28,7 +30,8 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
north: number;
east: number;
- constructor(protected fb: FormBuilder, private platform: Platform) {
+ constructor(protected fb: FormBuilder, private platform: Platform, private geolocation: Geolocation,
+ private domUtils: CoreDomUtilsProvider) {
super(fb);
}
@@ -94,4 +97,29 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
this.north = (value && parseFloat(value.content)) || null;
this.east = (value && parseFloat(value.content1)) || null;
}
+
+ /**
+ * Get user location.
+ *
+ * @param {Event} $event The event.
+ */
+ getLocation(event: Event): void {
+ event.preventDefault();
+
+ const modal = this.domUtils.showModalLoading('addon.mod_data.gettinglocation', true);
+
+ const options: GeolocationOptions = {
+ enableHighAccuracy: true,
+ timeout: 30000
+ };
+
+ this.geolocation.getCurrentPosition(options).then((result) => {
+ this.form.controls['f_' + this.field.id + '_0'].setValue(result.coords.latitude);
+ this.form.controls['f_' + this.field.id + '_1'].setValue(result.coords.longitude);
+ }).catch((error) => {
+ this.domUtils.showErrorModalDefault(error, 'Error getting location');
+ }).finally(() => {
+ modal.dismiss();
+ });
+ }
}
diff --git a/src/addon/mod/data/lang/en.json b/src/addon/mod/data/lang/en.json
index 219ec090c..54de61215 100644
--- a/src/addon/mod/data/lang/en.json
+++ b/src/addon/mod/data/lang/en.json
@@ -20,10 +20,12 @@
"expired": "Sorry, this activity closed on {{$a}} and is no longer available",
"fields": "Fields",
"foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)",
+ "gettinglocation": "Getting location",
"latlongboth": "Both latitude and longitude are required.",
"menuchoose": "Choose...",
"modulenameplural": "Databases",
"more": "More",
+ "mylocation": "My location",
"nomatch": "No matching entries found!",
"norecords": "No entries in database",
"notapproved": "Entry is not approved yet.",
diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json
index 748bb45f2..a82e7ef5a 100644
--- a/src/assets/lang/en.json
+++ b/src/assets/lang/en.json
@@ -493,10 +493,12 @@
"addon.mod_data.expired": "Sorry, this activity closed on {{$a}} and is no longer available",
"addon.mod_data.fields": "Fields",
"addon.mod_data.foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)",
+ "addon.mod_data.gettinglocation": "Getting location",
"addon.mod_data.latlongboth": "Both latitude and longitude are required.",
"addon.mod_data.menuchoose": "Choose...",
"addon.mod_data.modulenameplural": "Databases",
"addon.mod_data.more": "More",
+ "addon.mod_data.mylocation": "My location",
"addon.mod_data.nomatch": "No matching entries found!",
"addon.mod_data.norecords": "No entries in database",
"addon.mod_data.notapproved": "Entry is not approved yet.",