Last active
July 8, 2020 09:57
-
-
Save codenameone/16c2752f8eebbfe245cc to your computer and use it in GitHub Desktop.
More thorough example of the processing package from Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form hi = new Form("Location", new BoxLayout(BoxLayout.Y_AXIS)); | |
hi.add("Pinpointing Location"); | |
Display.getInstance().callSerially(() -> { | |
Location l = Display.getInstance().getLocationManager().getCurrentLocationSync(); | |
ConnectionRequest request = new ConnectionRequest("http://maps.googleapis.com/maps/api/geocode/json", false) { | |
private String country; | |
private String region; | |
private String city; | |
private String json; | |
@Override | |
protected void readResponse(InputStream input) throws IOException { | |
Result result = Result.fromContent(input, Result.JSON); | |
country = result.getAsString("/results/address_components[types='country']/long_name"); | |
region = result.getAsString("/results/address_components[types='administrative_area_level_1']/long_name"); | |
city = result.getAsString("/results/address_components[types='locality']/long_name"); | |
json = result.toString(); | |
} | |
@Override | |
protected void postResponse() { | |
hi.removeAll(); | |
hi.add(country); | |
hi.add(region); | |
hi.add(city); | |
hi.add(new SpanLabel(json)); | |
hi.revalidate(); | |
} | |
}; | |
request.setContentType("application/json"); | |
request.addRequestHeader("Accept", "application/json"); | |
request.addArgument("sensor", "true"); | |
request.addArgument("latlng", l.getLatitude() + "," + l.getLongitude()); | |
NetworkManager.getInstance().addToQueue(request); | |
}); | |
hi.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample code for using the Result class.
From the Codename One project