如何将EditText转换为地址?

时间:2014-05-09 18:27:30

标签: java android casting street-address

我正在尝试在EditText上获取地址的演员。

没有语法错误,但LogCat会抛出一个转换错误消息,但它不起作用。

geoPoint((Address)direction.getText()); // this is the cast

其中directionEditTextgeoPoint()定义如下:

public static GeoPoint geoPoint(Address direction){
    geoPoint = new GeoPoint(direction.getLongitude(), direction.getLatitude());
    return geoPoint;
}

想法是获取邮政地址的坐标

提前致谢!

2 个答案:

答案 0 :(得分:0)

都能跟得上!正如您在文档中看到的那样,AddressEditText无关。您只能“转换”来自同一类层次结构的对象。关于此主题还有另一个类似的问题,您可以参考:Casting objects in Java

您可以做的是获取地址的'String'值并使用

将其放在EditText中
EditText.setText(address.toString()); 
祝你好运!

答案 1 :(得分:0)

您需要使用Geocoder类从字符串中获取地址。看看这个答案:

How can I find the latitude and longitude from address?