【问题标题】:XML Parsing with regards to Reverse Geocode关于反向地理编码的 XML 解析
【发布时间】:2012-05-09 17:37:14
【问题描述】:

我正在尝试使用谷歌地图对我的位置进行反向地理编码,以检索我当前位置的街道名称和邮政编码。我尝试了许多使用本地化的项目,但我认为我的国家总是让它返回一个空值(我来自新加坡)。

使用 XML,我有点不确定我应该如何解析从 Google 地图获得的文件。

serverAddress = new URL("http://maps.google.com/maps/geo?q=" + Double.toString(loc.getLatitude()) + "," + Double.toString(loc.getLongitude()) + "&output=xml&oe=utf8&sensor=true&key=Hidden");

谁能给我一个前进的方向?我应该使用 Document 函数保存然后继续使用 SAX 解析文件吗?

【问题讨论】:

    标签: android xml eclipse sax reverse-geocoding


    【解决方案1】:

    试试这个:

        String urlStr = "http://maps.google.com/maps/geo?q=" + lat + "," + lon + "&output=json&sensor=false";
      String response = "";
      List<Address> results = new ArrayList<Address>();
      HttpClient client = new DefaultHttpClient();
    
      Log.d("ReverseGeocode", urlStr);
      try {
             HttpResponse hr = client.execute(new HttpGet(urlStr));
             HttpEntity entity = hr.getEntity();
    
             BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
    
             String buff = null;
             while ((buff = br.readLine()) != null)
                response += buff;
              } catch (IOException e) {
                  e.printStackTrace();
           }
    

    有关 ReverseGeocode 的更多详细信息,请参阅 this example

    【讨论】:

    • 好的,谢谢。我会试试这个。可悲的是,链接似乎是关于 JSON 的,到目前为止我还没有尝试过。感谢您的帮助!
    猜你喜欢
    • 2014-04-06
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    相关资源
    最近更新 更多