我试图通过从编辑文本中获取输入来搜索地图,我有两个编辑文本;一个用于源位置,另一个用于目的地,当用户输入源目标并移动到下一个(或者我们可以说失去焦点时)比“用户输入的地点在地图上用标记指出”。如何在Android中编辑文本中的文本完成后调用方法
但是在这里,当我输入GUJRAT大学比它需要GUJRAT和大学作为不同的不同价值。
et.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// findPlaceWaypoints();
}
@Override
public void afterTextChanged(Editable s) {
findPlaceWaypoints();
}
});
但它搜索每一个字即中央PRADES然后搜索中央和PRADES和相关中央PRADES每一个可能的话。我希望所有的文本都是ONE VALUE这是在编辑文本中键入。
这是我findPlaceWaypoints方法:
private void findPlaceWaypoints() {
String location = et.getText().toString().toLowerCase();
if (location == null || location.equals("")) {
// Toast.makeText(getBaseContext(), "No Place is entered", Toast.LENGTH_SHORT).show();
return;
}
String url = "https://maps.googleapis.com/maps/api/geocode/json?";
try {
// encoding special characters like space in the user input place
location = URLEncoder.encode(String.valueOf(location), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String address = "address=" + location;
String sensor = "sensor=true";
// url , from where the geocoding data is fetched
url = url + address + "&" + sensor;
// Instantiating DownloadTask to get places from Google Geocoding service
// in a non-ui thread
DownloadTask downloadTask = new DownloadTask();
// Start downloading the geocoding places
downloadTask.execute(url);
}
你能详细解释你的查询吗? –
你需要它来进行搜索吗? –
如果你用相同的编辑文本编写它,那么它就像古吉拉特大学一样。 –