如何获取用户输入的名称并在edittext中搜索相应的位置 [英] how to get the name entered by the user and search that respective location in edittext
问题描述
我可以将Google地图放置在我的android手机中。我把谷歌地图的搜索选项。如果用户给出位置并单击按钮搜索意味着它在谷歌地图中找到位置。现在我想显示相对位置,当用户在Edittext中给出位置名称。请给我任何参考.....
我试试这个按钮的代码点击
if(v ==搜索){
Geocoder geo = new Geocoder(getApplicationContext(),
Locale.getDefault());
尝试{
列表<地址>地址= 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);
列表< Overlay> lisOverlays = view.getOverlays();
lisOverlays.clear();
lisOverlays.add(mapOverlay);
}
按钮搜索点击表示它也显示位置。我想根据用户搜索在编辑文本中显示位置使用以下代码接受来自用户的输入和地图上的搜索位置 。
字符串值= editText1.getText()。toString();
//做一些有价值的事!
Log.d(value,value);
Geocoder geoCoder = new Geocoder(getBaseContext(),Locale.getDefault());
尝试{
列表<地址>地址= geoCoder.getFromLocationName(
值,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();
}
需要进行一些更改
i can place Google map in my android mobile. i put search option for google map. if the user give the location and click button search means it find the location in google map. now i want display relative location when the user give the location name in Edittext..Please give me any reference.....
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);
}
the button search click means it shows location also . i want displays the locations according to user search in edit text
Use following code to accept input from user and search place on map.
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();
}
Some changes required
这篇关于如何获取用户输入的名称并在edittext中搜索相应的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!