如何在blackberry中使用经度和纬度获取当前地址



你能告诉我如何在黑莓中使用经度和纬度获取当前地址吗?

我找到了这个代码,但是这个代码中的getConnectionStringForGoogleMap()是什么?

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");
    }        
}

我怀疑您正在查找的代码会按照此处的规范向URL添加一个连接字符串:

HTTP或套接字连接的不同方法

这只是为了让它可以连接到互联网。我建议您使用网络连接API(ConnectionFactory),而不是使用它,您可以在这里找到描述:

网络API

关于这个代码的实际工作方式,它似乎使用了一些Google API,所以你需要查找相关的Google API来了解它在做什么以及如何使用它

使用谷歌进行反向地理编码的另一种选择是让黑莓服务来进行。这将适用于具有完整黑莓数据计划的设备。我建议你复习一下名为:中的地理编码和反向地理编码的部分

位置API开始完成

最新更新