List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Friday, June 10, 2016

Blackberry Get User Address from Lattitude and Longitude

  getLocationFromGoogleMaps(43.4631,-80.5207);

  private static void getLocationFromGoogleMaps(double _lattitude, double _longitude) {

    String fullAddress = "";
    HttpConnection conn = null;
    InputStream in = null;
    ByteArrayOutputStream out = null;
    try {
        String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + _lattitude + "," + _longitude;
        conn = (HttpConnection) Connector.open(url, Connector.READ);
        conn.setRequestMethod(HttpConnection.GET);
        int code = conn.getResponseCode();
        if (code == HttpConnection.HTTP_OK) {
        in = conn.openInputStream();
        out = new ByteArrayOutputStream();
        byte[] buffer = new byte[in.available()];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer);
        }
        out.flush();
        String response = new String(out.toByteArray());
        JSONObject resObject = new JSONObject(response);
        JSONArray result = resObject.getJSONArray("results");

        if (result.length() > 0) {
            JSONObject dict = result.getJSONObject(0);
            System.out.println("**Resp :**" + dict.getString("formatted_address"));
            fullAddress = dict.getString("formatted_address");
            Dialog.alert(fullAddress);
        } else {
           //error
        }

        }
    } catch (Exception e) {
        Dialog.alert(e.getMessage());
       }

    }

2 comments:

  1. I don’t know how should I give you thanks! I am totally stunned by your article. You saved my time. Thanks a million for sharing this article.

    ReplyDelete
  2. Great article, Thanks for your great information, the content is quiet interesting. I will be waiting for your next post.

    ReplyDelete