2017-02-14 110 views
0
ConnectionDetector cd = new ConnectionDetector(Healthcare.this); 
isInternetPresent = cd.isConnectingToInternet(); 
if (isInternetPresent) { 
GPSTracker gps = new GPSTracker(this); 
Geocoder geoCoder = new Geocoder(Healthcare.this, Locale.getDefault()); 
if (gps.canGetLocation()) { 
    try { 
      latitudecur = gps.getLatitude(); 
      longitudecur = gps.getLongitude(); 
      Log.d("latlong",""+latitudecur+longitudecur); 
      List<Address> address = geoCoder.getFromLocation(latitudecur, longitudecur, 1); 
         Log.e("FInalAddress1",""+address.size()); 
         ## Heading ## 

        } catch (NullPointerException e) { 
         // TODO: handle exception 
        } catch (NumberFormatException e) { 
         // TODO: handle exception 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } else { 

       } 
      } 

我在代碼中寫了上面的代碼,但在Log.e(「FInalAddress1」,「」+ address.size()); address.getsize()得到0.沒有得到像這樣的代碼,如地方,地址等 我的問題上面的代碼是什麼? 請幫助 感謝錯誤:無法從地址解析器獲取地址

+0

它需要互聯網連接提供的API。你把互聯網許可證明了嗎? – lal

+0

做了'latlong'打印值? – rafsanahmad007

+0

是的,我把清單中的互聯網權限,並獲得經緯度 – Makvin

回答

0

如果它不工作,你可以調用谷歌

JSONObject jsonObject = getJsonResponse("http://maps.google.com/maps/api/geocode/json?latlng=" + mLatitude + "," + mLogitude + "&sensor=true"); 
    if (jsonObject != null) { 
     try { 
      JSONArray jsonArray = jsonObject.getJSONArray("results"); 
      for (int i = 0; i < jsonArray.length(); i++) { 
       JSONObject addressResult = jsonArray.getJSONObject(i); 
       String formattedAddress = addressResult.getString("formatted_address"); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
    } 
+0

謝謝,但我知道解決方案,但我想使用地理編碼器 – Makvin