Android 如何获取用户输入的名称并在edittext中搜索相应的位置
我可以把谷歌地图放在我的安卓手机上。我把谷歌地图的搜索选项。如果用户给出了位置并单击按钮搜索,则表示它在谷歌地图中找到了位置。现在我想在用户在Edittext中给出位置名称时显示相对位置..请给我任何参考Android 如何获取用户输入的名称并在edittext中搜索相应的位置,android,google-maps,Android,Google Maps,我可以把谷歌地图放在我的安卓手机上。我把谷歌地图的搜索选项。如果用户给出了位置并单击按钮搜索,则表示它在谷歌地图中找到了位置。现在我想在用户在Edittext中给出位置名称时显示相对位置..请给我任何参考 i try this code of button click if (v == search) { Geocoder geo = new Geocoder(getApplicationContext(), Locale.getD
i try this code of button click
if (v == search) {
Geocoder geo = new Geocoder(getApplicationContext(),
Locale.getDefault());
try {
List<Address> addresses = geo.getFromLocationName(location
.getText().toString(), 5);
if (addresses.size() > 0) {
GeoPoint p = new GeoPoint((int) (addresses.get(0)
.getLatitude() * 1E6), (int) (addresses.get(0)
.getLongitude() * 1E6));
controller.animateTo(p);
controller.setZoom(12);
MapOverlay mapOverlay = new MapOverlay(getApplicationContext(),p);
List<Overlay> lisOverlays = view.getOverlays();
lisOverlays.clear();
lisOverlays.add(mapOverlay);
}
我尝试点击按钮的代码
如果(v==搜索){
Geocoder geo=新的地理编码器(getApplicationContext(),
Locale.getDefault());
试一试{
列表地址=geo.getFromLocationName(位置
.getText().toString(),5);
如果(地址.size()>0){
地质点p=新的地质点((int)(addresses.get(0)
.getLatitude()*1E6,(int)(地址.get(0)
.getLongitude()*1E6));
控制器.animateTo(p);
控制器。设置缩放(12);
MapOverlay MapOverlay=新的MapOverlay(getApplicationContext(),p);
List lisOverlays=view.getOverlays();
lisOverlays.clear();
lisOverlays.add(mapOverlay);
}
“搜索”按钮单击意味着它还显示位置。我希望根据编辑文本中的用户搜索显示位置。使用以下代码接受用户输入并在地图上搜索位置
String value = editText1.getText().toString();
// Do something with value!
Log.d("value", value);
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(
value, 5);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
String value=editText1.getText().toString();
//做一些有价值的事情!
Log.d(“值”,值);
Geocoder Geocoder=新的地理编码器(getBaseContext(),Locale.getDefault());
试一试{
列表地址=geoCoder.getFromLocationName(
价值,5);
字符串add=“”;
如果(地址.size()>0){
p=新的地质点(
(int)(addresses.get(0.getLatitude()*1E6),
(int)(addresses.get(0.getLongitude()*1E6));
司马迁(p),;
mapView.invalidate();
}
}捕获(IOE异常){
e、 printStackTrace();
}
需要进行一些更改我尝试使用您的代码,但在输入edittext时无法显示相对位置