I need to insert geo coordinates inside context
Hi,
I'm trying to insert gps positions as Extensions into Context Object.
When I call the object i can't find how to insert the values.
This is the code I use to write a context part in the statement
var objContext = new Context(); objContext.extensions = new TinCan.Extensions();
how can now insert the user gps positions?
"http://id.tincanapi.com/extension/latitude" = userLatCoord; "http://id.tincanapi.com/extension/longitude" = userLongCoord;
Thanks in advance...
Andrea
Unfortunately there is not currently an interface for adjusting the extensions map on existing objects. This is definitely an oversight in the API. For now I think you would have to work around this by passing the full list of extension properties during construction of the object. You can pass it a JObject. To edit you'd have to grab an existing JObject via the ToJObject method, edit that directly, create a new object and then store it back to your Context (not ideal I realize).
The TinCanJava object that is effectively the same has added an interface for manipulating the Extensions object, you can see it starting here:
https://github.com/RusticiSoftware/TinCanJava/blob/master/src/main/java/com/rusticisoftware/tincan/Extensions.java#L63
When we get around to adding this interface to TinCan.NET it will very likely look the same. If you want to do that and submit a clean PR (IOW no extraneous changes to the .proj, etc.) then it will eventually get included. I can't give a timeframe on review+merge.
All right I could try to run with Object, because I really have this:
"context": { "extensions": {}, so…if I grab this like a Object with ToJObject method, I have…empty could edit with my values…and then? How could I pass back to the specific statement? Could you provide me an example in c# Thanks and regards Andrea
Il giorno 19 gen 2018, alle ore 14:26, Brian J. Miller [email protected] ha scritto:
ToJObject
@brianjmiller @uest555 Hi. Was there ever a solution to this?
I have been trying to add extensions to my statements without any luck.
I did this:
statement.result.extensions = new TinCan.Extensions();
It created an empty array.
To add to the extension, I tried what @brianjmiller suggested. I did this:
JObject extensionsObject = new JObject();
extensionsObject.Add("http://id.tincanapi.com/extension/duration", value);
statement.result.extensions = new TinCan.Extensions(extensionsObject);
Doing the above I get this error: The type 'JObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
It seems that it is looking for a different version of Newtonson.Json. I've been looking around but it seems that it does not exist.
Any help would be great. Thanks.
Nevermind. I realized I was using an older version of Newtonsoft.Json. I updated it and it worked perfectly.
@uest555 I know this is a very old post but this worked for editing your extensions.
JObject extensionsObject = new JObject();
extensionsObject.Add("http://id.tincanapi.com/extension/duration", value);
statement.result.extensions = new TinCan.Extensions(extensionsObject);
Ooooh …sooooo many thanks!!!!!!!!!!!!!!!!!!!
Il giorno 19 ago 2020, alle ore 03:22, Jonathan Valderrama [email protected] ha scritto:
Nevermind. I realize I was using an older version of Newtonsoft.Json. I updated it and it worked perfectly.
@uest555 https://github.com/uest555 I know this is a very old post but this worked for editing your extensions.
JObject extensionsObject = new JObject(); extensionsObject.Add("http://id.tincanapi.com/extension/duration", value); statement.result.extensions = new TinCan.Extensions(extensionsObject); — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RusticiSoftware/TinCan.NET/issues/33#issuecomment-675797792, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2RBP6RMXOU6OVKQTXMCT3SBMSMNANCNFSM4EMRDTUQ.