【问题标题】:blackberry gps getting current Location Address?黑莓GPS获取当前位置地址?
【发布时间】:2011-04-08 11:58:18
【问题描述】:

您好,我是黑莓应用程序开发的新手。我想获取当前 gps 位置详细信息。我已成功获取纬度和经度,但我不知道如何获取当前地址。谁能给我一个示例?谢谢提前。

【问题讨论】:

    标签: blackberry


    【解决方案1】:

    您要查找的内容称为“反向地理编码”。 RIM 在 BB 平台上有一个example of exactly how to do this(好吧,无论如何都是一种方法)。

    【讨论】:

    • 我如何检查值?在可运行线程内不允许字段(标签字段,文本字段)我如何检查 addrinfo 值?请回复我
    • 听起来您应该研究一下线程在 BB 应用程序中的使用。例如,您可能会看到 Blackberry UI Threading - The Very Basics:thinkingblackberry.com/archives/182
    【解决方案2】:

    您可以使用谷歌地图来解决您的问题,如果您请求纬度和经度,谷歌地图将根据您的选择返回一个 JSON(或 XML)。

    网址是:http://maps.google.com/maps/geo?json&ll="+_lattitude+","+_longitude

    这将以JSON格式返回给定经纬度的所有详细信息,并且您必须解析谷歌地图返回的JSON。

    您可以使用以下代码:

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

    注意:我使用 FacebookBlackBerrySDK-0.3.5-src 来解析 JSON,或者您也可以使用 XML。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 2016-07-30
      相关资源
      最近更新 更多