我有兩個問題,第一個是,我有獲得一個地址,並將其打印到的EditText一個字符串構建:Android的GPS定位及getFromLocation
Geocoder mGC = new Geocoder(context,Locale.getDefault());
address = mGC.getFromLocation(lat, lng, 1);
if (address !=null){
Address currentAddr = address.get(0);
mSB = new StringBuilder();
for (int i=0; i<currentAddr.getMaxAddressLineIndex(); i++){
mSB.append(currentAddr.getAddressLine(i)).append(", ");
}
outputText.setText(mSB.toString());
}
的問題是隨機的address = mGC.getFromLocation(lat, lng, 1);
線返回一個空指針異常。有時候它會工作幾天......然後突然它有一個空指針異常;有誰知道爲什麼?
另外我的第二個問題是我的GPS定位需要一些時間,我正在使用GPS衛星;有沒有一種方法可以先使用網絡提供的信息,然後使用GPS衛星進行更快的修復?
當發生這種情況時,可能是lat或lng都爲null。 –