I'm having trouble loading a geojson file from the api (gdelta project) into codename one. The json comes in a file from this api that you have to download, however I haven't been able to find online or myself a way to download this file into my program. I've already tried putting it in Storage but I can't seem to be able to physically find where to put my file.
1
votes
1 Answers
0
votes
You can download the file to storage and give it any name you want but I'm guessing that what you are actually asking is how to connect to a webservice and parse the resulting JSON data. I don't have an immediate sample for geojson but I have samples for Googles geocoding webservices which should be pretty darn close. As a side note these samples are from the work I've been doing on the Uber clone application in the online course...
public static void findLocation(String name, SuccessCallback<Coord> location) {
Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("address", name).
queryParam("key", Globals.GOOGLE_GEOCODING_KEY).
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
Map geometryMap = (Map)firstResult.get("geometry");
Map locationMap = (Map)geometryMap.get("location");
double lat = Util.toDoubleValue(locationMap.get("lat"));
double lon = Util.toDoubleValue(locationMap.get("lng"));
location.onSucess(new Coord(lat, lon));
}
}
});
}
The result is returned into the Map object which follows the hierarchy of the JSON data. You can place a breakpoint in the code and inspect the map value to see the result.