Geocoder 屏蔽了我的 android 应用
Geocoder blocks my android app
这是我的代码:
private void getGeocoderForCheckout(int section) {
Log.i("","current address getGeocoderForCheckout");
setViewOver();
loader.setVisibility(View.VISIBLE);
sect = section;
selectedSD = currentPlace;
PSLocationCenter.getInstance().pref.setCheckoutType(context, "Current address");
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
Log.i("","current address getGeocoderForCheckout");
try {
Log.i("","current address getGeocoderForCheckout1" + currentPlace);
double lng = currentPlace.getLon();
Log.i("","current address getGeocoderForCheckout1 lat lng: " + currentPlace.getLat() + "..." + lng);
List<Address> address = geocoder.getFromLocation(currentPlace.getLat(), lng, 1);
Log.i("","current address getGeocoderForCheckout1");
if (address.size() > 0) {
String title = address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "";
new PlacesAPI(context, currentAddressListener).execute(PlacesAPI.TYPE_AUTOCOMPLETE, "&input=" + URLEncoder.encode(title, "utf8"));
}
} catch (Exception e) {
Log.i("","current address errorr: "+ e.getMessage());
removeViewOver();
Toast.makeText(context, context.getString(R.string.geocoder_error), Toast.LENGTH_SHORT).show();
loader.setVisibility(View.GONE);
Utils.appendLog("onmap long click errror : " + e.getMessage());
e.printStackTrace();
}
}
我的问题是它总是在这一行阻止应用程序:
List<Address> address = geocoder.getFromLocation(currentPlace.getLat(), lng, 1);
这是我得到的日志:
09-11 12:22:59.725 25648-25648/nl.hgrams.passenger I/: current address has internet
09-11 12:22:59.725 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout
09-11 12:22:59.729 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout
09-11 12:22:59.730 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout1nl.hgrams.passenger.model.Destination@3c19358f
09-11 12:22:59.731 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout1 lat lng: 52.3724299...4.9088149
我尝试调试该应用程序,但在进入 geocoder.getFromLocation 行后,它在 Looper 处停了下来。从那一刻起,应用程序就没有响应了。
编辑:如果我按下 "getFromLocation" 功能将我带到它。它带我进入 Geocoder.java 这个功能:
public List<Address> getFromLocation(double latitude, double longitude, int maxResults)
throws IOException {
if (latitude < -90.0 || latitude > 90.0) {
throw new IllegalArgumentException("latitude == " + latitude);
}
if (longitude < -180.0 || longitude > 180.0) {
throw new IllegalArgumentException("longitude == " + longitude);
}
try {
List<Address> results = new ArrayList<Address>();
String ex = mService.getFromLocation(latitude, longitude, maxResults,
mParams, results);
if (ex != null) {
throw new IOException(ex);
} else {
return results;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocation: got RemoteException", e);
return null;
}
}
其中:
mService.getFromLocation(latitude, longitude, maxResults,
mParams, results);
为红色并表示:"cannot resolve method".....
PS:我在其他地方也用过这个功能,还可以。所以我不知道这里可能出了什么问题。
尝试在后台线程中调用 getFromLocation()
。
来自 documentation :
It may be useful to call this method from a thread separate from your
primary UI thread.
这是我的代码:
private void getGeocoderForCheckout(int section) {
Log.i("","current address getGeocoderForCheckout");
setViewOver();
loader.setVisibility(View.VISIBLE);
sect = section;
selectedSD = currentPlace;
PSLocationCenter.getInstance().pref.setCheckoutType(context, "Current address");
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
Log.i("","current address getGeocoderForCheckout");
try {
Log.i("","current address getGeocoderForCheckout1" + currentPlace);
double lng = currentPlace.getLon();
Log.i("","current address getGeocoderForCheckout1 lat lng: " + currentPlace.getLat() + "..." + lng);
List<Address> address = geocoder.getFromLocation(currentPlace.getLat(), lng, 1);
Log.i("","current address getGeocoderForCheckout1");
if (address.size() > 0) {
String title = address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "";
new PlacesAPI(context, currentAddressListener).execute(PlacesAPI.TYPE_AUTOCOMPLETE, "&input=" + URLEncoder.encode(title, "utf8"));
}
} catch (Exception e) {
Log.i("","current address errorr: "+ e.getMessage());
removeViewOver();
Toast.makeText(context, context.getString(R.string.geocoder_error), Toast.LENGTH_SHORT).show();
loader.setVisibility(View.GONE);
Utils.appendLog("onmap long click errror : " + e.getMessage());
e.printStackTrace();
}
}
我的问题是它总是在这一行阻止应用程序:
List<Address> address = geocoder.getFromLocation(currentPlace.getLat(), lng, 1);
这是我得到的日志:
09-11 12:22:59.725 25648-25648/nl.hgrams.passenger I/: current address has internet
09-11 12:22:59.725 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout
09-11 12:22:59.729 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout
09-11 12:22:59.730 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout1nl.hgrams.passenger.model.Destination@3c19358f
09-11 12:22:59.731 25648-25648/nl.hgrams.passenger I/: current address getGeocoderForCheckout1 lat lng: 52.3724299...4.9088149
我尝试调试该应用程序,但在进入 geocoder.getFromLocation 行后,它在 Looper 处停了下来。从那一刻起,应用程序就没有响应了。
编辑:如果我按下 "getFromLocation" 功能将我带到它。它带我进入 Geocoder.java 这个功能:
public List<Address> getFromLocation(double latitude, double longitude, int maxResults)
throws IOException {
if (latitude < -90.0 || latitude > 90.0) {
throw new IllegalArgumentException("latitude == " + latitude);
}
if (longitude < -180.0 || longitude > 180.0) {
throw new IllegalArgumentException("longitude == " + longitude);
}
try {
List<Address> results = new ArrayList<Address>();
String ex = mService.getFromLocation(latitude, longitude, maxResults,
mParams, results);
if (ex != null) {
throw new IOException(ex);
} else {
return results;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocation: got RemoteException", e);
return null;
}
}
其中:
mService.getFromLocation(latitude, longitude, maxResults,
mParams, results);
为红色并表示:"cannot resolve method".....
PS:我在其他地方也用过这个功能,还可以。所以我不知道这里可能出了什么问题。
尝试在后台线程中调用 getFromLocation()
。
来自 documentation :
It may be useful to call this method from a thread separate from your primary UI thread.