0
我有地理編碼器函數的「null」結果。我使用地理編碼器顯示latitide &經度的地址。這是我的代碼項目的一部分。 如何固定?「null」地理編碼器的結果
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);
}
你*總是*爲空嗎? – Hulk
是的。緯度和經度自動檢測。 –