How to store JSON Object with GeoTag in Corona?

0 votes

How do I store a JSON object with a GeoTag in Corona SDK? (The document says “Coming soon…”)

Thanks,

Thomas

 

asked Apr 8, 2014 in App42 Cloud API-BaaS by office (12 points)

1 Answer

0 votes

Hi office;

1- Use this Code Snippet -

local JSON = require("App42-Lua-API.JSON") 
local dbName  = "<Your_DataBase_Name>"  
local collectionName = "<Your_Collection_Name>"  
local json = "{\"name\":\"Nick\",\"age\":30,\"phone\":\"xxx-xxx-xxx\"}"  
local gp = require("App42-Lua-API.GeoTag")  
gp:setLat(-73.70000);
gp:setLng(-40);
storageService:setGeoTag(gp);
storageService:insertJSONDocument(dbName, collectionName,json,callBack);
function callBack:onSuccess(object)
print("Response is :"..object:getStrResponse());
print("Response is :"..JSON:encode(object));
print("Dbname is "..object:getDbName());  
print("Collection Name is "..object:getCollectionName());  
print("getDocId is "..object:getJsonDocList():getDocId())
print("getCreatedAt  is "..object:getJsonDocList():getCreatedAt());  
print("getUpdatedAt is "..object:getJsonDocList():getUpdatedAt());  
print("Doclist Name is "..JSON:encode(object:getJsonDocList():getJsonDoc()));  
print("lat is "..JSON:encode(object:getJsonDocList():getLocation():getLat())); 
print("lng is "..JSON:encode(object:getJsonDocList():getLocation():getLng()));
end  
function callBack:onException(object)
print("Message is "..object:getAppErrorCode()); 
print("Message is "..object:getHttpErrorCode()); 
print("Message is "..object:getMessage()); 
print("Message is "..object:getDetails()); 
end
answered Apr 9, 2014 by samita.mahajan (60 points)
Perfect, thanks. And how do I use a GeoQuery to find JSON documents by their geo location?

Update: Found it here http://api.shephertz.com/app42-docs/nosql-storage-service/#find_documents_by_location
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...