blackberry gps getting current Location Address?

混江龙づ霸主 提交于 2019-12-24 05:52:12

问题


Hi i am new to blackberry application development.I want to get current gps location detail.I had successfully got the latitude and longitude but i dont know how to get the current address.can any one give me a sample?Pls thanks in advance.


回答1:


What you are looking for is called "Reverse Geocoding." RIM has an example of exactly how to do this on the BB platform (well, one way to do it anyway).




回答2:


You can use Google map to resolve your issue, Google map will return a JSON (or XML) according to your choice if you request with a lattitude and longitude.

The url is: http://maps.google.com/maps/geo?json&ll="+_lattitude+","+_longitude

This will return all the details of the given latitude and longitude in JSON format,And you have to parse the JSON returned by Google map.

You can use the below 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");
    }        
}

Note: I use a FacebookBlackBerrySDK-0.3.5-src to parse JSON or you can XML aslo.



来源:https://stackoverflow.com/questions/5594715/blackberry-gps-getting-current-location-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!