MOBILE-2159 data: Geolocation button in latlong fields
parent
ef40dfe74c
commit
e83ff1b711
|
@ -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",
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
<ion-input type="text" [formControlName]="'f_'+field.id+'_1'" maxlength="10"></ion-input>
|
||||
<span class="placeholder-icon" item-right>°E</span>
|
||||
</div>
|
||||
<div *ngIf="mode == 'edit'" class="addon-data-lantlong">
|
||||
<button ion-button icon-left (click)="getLocation($event)">
|
||||
<ion-icon name="locate"></ion-icon>
|
||||
{{ 'addon.mod_data.mylocation' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
<core-input-errors *ngIf="error && mode == 'edit'" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
|
||||
</span>
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}} (<a href=\"{{$a.reseturl}}\">Reset filters</a>)",
|
||||
"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.",
|
||||
|
|
|
@ -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}} (<a href=\"{{$a.reseturl}}\">Reset filters</a>)",
|
||||
"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.",
|
||||
|
|
Loading…
Reference in New Issue