how to get current address using longitude and latitude in blackberry

300 Views Asked by At

can you please tell me how to get current address using longitude and latitude in blackberry ?

I found this code, but what is this getConnectionStringForGoogleMap() in this code ?

private void getLocationFromGoogleMaps() {
    try {
        StreamConnection s = null;
        InputStream iStream = null;        
        s=(StreamConnection)javax.microedition.io.Connector.open("http://maps.google.com/maps/geo?json&ll="+_lattitude+","+_longitude+getConnectionStringForGoogleMap());//&deviceside=false&ConnectionType=mds-public"

        HttpConnection con = (HttpConnection)s; 
        con.setRequestMethod(HttpConnection.GET);
        con.setRequestProperty("Content-Type", "//text");
         int status = con.getResponseCode();
         if (status == HttpConnection.HTTP_OK)
         {
             iStream=s.openInputStream();                    
             int len=(int) con.getLength();
             byte[] data = new byte[8000];                    
             byte k;
             String result="";
             while((k = (byte)iStream.read()) != -1) {
                 result = result+(char)k;
             }                  
             try {
                  JSONObject jsonObjectMapData=new JSONObject(result);                                                    
                  JSONArray  jsonaryPlaceMark = jsonObjectMapData.getJSONArray("Placemark");
                  JSONObject address= jsonaryPlaceMark.getJSONObject(0);
                 String placeName=address.getString("address");
                 if(placeName!=null)
                     lblLoc.setText(address.getString("address"));
                 else
                     lblLoc.setText("Location information currently unavilable");
             } catch (Exception e) {
                 lblLoc.setText("location information Currently Unavilable");
             }
         }
    }catch (Exception e) {
        System.out.println(e);
        lblLoc.setText("location information Currently Unavilable");
    }        
}
1

There are 1 best solutions below

0
On

I suspect the code you are looking for will add a connection string to the URL following the specification here:

Different-ways-to-make-an-HTTP-or-socket-connection

This is just so that it can connect to the Internet. Instead of using this I recommend that you use the Network Connection API (ConnectionFactory), which you will find described here:

Network API

Regarding the actual way this code works, it appears to using some Google API, so you will need to look up the relevant Google APIs to find out what it is doing and how to use it.

The alternative to using Google to do this reverse geocoding, is to get the BlackBerry Services to do it. This will work on devices that have a full BlackBerry Data plan. I suggest you review the section called: Geocoding and Reverse Geocoding in

Location-APIs-Start-to-finish