Can I programmatically set a value for the location field?

When the user has a disabled GPS, the current location cannot be retrieved. For this case, a user will enter the latitude and longitude manually. It need to be saved in the same field (with type location) like as it’s normal captured coordinates by capture-coordinates component.

I’ve tried to do that:

view.ticket.LOCATION = new Location({
   "latitude": view.latitude,
   "longitude": view.longitude
});

But I get an error:

Reference Error: Location is not defined

Is there a way to define a new Location object?

Hi Khilda

The below should work

var newLocation = {
  "latitude": -16.92593042155752,
  "longitude": 10.15002065192829,
  "altitude": null, // or some default value
  "horizontal_accuracy": null, // or some default value
  "vertical_accuracy": null, // or some default value
  "timestamp": (new Date()).toISOString() // or null or some default value
};
view.ticket.LOCATION = newLocation;
1 Like

I tried this option, but the editor shows an error, so I didn’t use it.

image

Now I tried it, and yes - it works correctly. Is it possible to somehow avoid the error in the editor? Or will it affect anything?

I’m using it like that now, but I’m not sure that

“toJSON”: null

is correct.

view.ticket.LOCATION = {
“latitude”: view.latitude,
“longitude”: view.longitude,
“altitude”: null,
“horizontal_accuracy”: null,
“vertical_accuracy”: null,
“timestamp”: new Date(),
“toJSON”: null
};

I would exclude the toJSON in your newLocation object and just ignore the editor warning.

Luckily it’s just a warning, and not an error.

Got it. Thanks for your help, Tielman!

1 Like