2011-04-08 176 views
1

嗨,我是黑莓应用程序开发的新手。我想获得当前的gps位置细节。我已经成功地获得了经纬度,但我不知道如何获得当前的地址。任何人都可以给我一个样本?请感谢提前。blackberry gps获取当前位置地址?

回答

3

你在找什么叫做“反向地理编码”。 RIM在BB平台上有一个example of exactly how to do this(好吧,无论如何要做到这一点)。

+0

我该如何检查值?在可运行的线程内没有字段允许像(labelfield,textfield)如何检查addrinfo值?请回复我 – 2011-04-08 13:33:09

+0

这听起来像你应该做一些调查在BB应用中使用线程。例如,您可能会看到Blackberry UI线程 - 非常基础:http://www.thinkingblackberry.com/archives/182 – 2011-04-08 16:02:16

3

您可以使用Google地图解决您的问题,如果您请求经度和纬度,Google地图将根据您的选择返回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 ASLO。