Android动态显示位置到TextView

时间:2012-12-07 12:53:01

标签: android xml

我有一个通过EditTexts接收用户输入的活动。我正在进行的项目也将充分利用位置值。

当用户拍照时,他们会自动转移到DataEntry活动。我想要实现的是使用位置值自动填充两个TextView,并且显然具有稍后要使用的变量。

下面的图片将说明我的意思。我已经尝试了一些方法,但不断出现眩晕错误。任何人都可以帮助我吗?

enter image description here

我希望用lat和long填充位置值下的空白textviews。我有两种方法来获取Lat和Long值,然后我将结果字符串分配给一个静态变量,该变量填充TextView,但我无法得到它来产生结果。

public Location getLongitude(){
     LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
     Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
     longitude = location.getLongitude();
     longitudeString = String.valueOf(longitude);
     return longitudeString;
 }

public Location getLatitude(){
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    latitude = location.getLatitude();
    latitudeString = String.valueOf(latitude);
    return latitudeString;

}*/

1 个答案:

答案 0 :(得分:1)

替换此

public Location getLatitude(){
//your Code here;
}

public Location getLongitude(){
//your Code here;
}

这一个

public String getLatitude(){
//your Code here;
}
public String getLatitude(){
//your Code here;
}