【问题标题】:how to get current address using longitude and latitude in blackberry如何在黑莓中使用经度和纬度获取当前地址
【发布时间】:2013-12-02 09:17:43
【问题描述】:

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

我找到了这段代码,但这段代码中的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");
    }        
}

【问题讨论】:

  • 您需要支持哪个最低 BlackBerry OS 版本?
  • OS 5 是最低操作系统

标签: blackberry java-me


【解决方案1】:

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

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

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

Network API

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

使用 Google 执行反向地理编码的替代方法是让 BlackBerry 服务执行此操作。这适用于具有完整 BlackBerry Data 计划的设备。我建议您查看名为:地理编码和反向地理编码的部分

Location-APIs-Start-to-finish

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多