【发布时间】: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