我可以把谷歌地图放在我的安卓手机里。我把谷歌地图的搜索选项。如果用户给出位置并单击按钮搜索,则意味着它可以在谷歌地图中找到该位置。现在我想显示相对位置时,用户给的位置名称在编辑文本..请给我任何参考…..
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);
}
单击“搜索”按钮意味着它还显示位置。我想在编辑文本中根据用户搜索显示位置
最佳答案
使用以下代码接受来自用户的输入并搜索地图上的位置。
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();
}
需要进行一些更改
关于android - 如何获得用户输入的名称并在edittext中搜索相应的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12559924/