【问题标题】:"null" result of geocoder地理编码器的“空”结果
【发布时间】:2016-07-27 05:00:42
【问题描述】:

我有地理编码器功能的“空”结果。我使用地理编码器显示纬度和经度的地址。这是我的代码项目的一部分。 它是如何固定的?

goecoder 代码:

public void getMyLocationAddress() {
    Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);
    try {     
          //Place your latitude and longitude
          List<Address> addresses = geocoder.getFromLocation(latMosque,lonMosque, 1);

        if(addresses != null) {

              Address fetchedAddress = addresses.get(0);
              StringBuilder strAddress = new StringBuilder();

              for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) {
                    strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
              }           
            lokasi ="lokasi : "+strAddress.toString();

          }   
          else
            lokasi = "lokasi tidak ditemukan";
    } 
    catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             Toast.makeText(getApplicationContext(),"Could not get address..!", Toast.LENGTH_LONG).show();
    }
}

要显示的代码,使用画布,而不是 xml..

protected void onDraw(Canvas canvas) {
     Paint paint = mPaint;
    Paint paint5 =mPaint;
    paint5.setTextSize(20);
    paint5.setColor(Color.RED);

    canvas.drawText("Alamat : "+ lokasi , 50, 100, paint5);
 }

【问题讨论】:

  • 总是得到null吗?
  • 是的.. 经纬度自动检测。

标签: android reverse reverse-geocoding


【解决方案1】:

我假设您使用的是android.location.Geocoder。引用文档:

如果未找到匹配项或没有可用的后端服务,则返回 null 或空列表。

因此,您的后端服务可能不可用 - 或者您所在的位置没有数据。

【讨论】:

    猜你喜欢
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2011-09-15
    • 1970-01-01
    相关资源
    最近更新 更多