I need to insert geo coordinates inside context
uest555 opened this issue · 5 comments
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:
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.
@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);