0

我正在尝试保留所有读取的 GPS 位置的列表。我希望它们被格式化:
long:(5 digits) and lat:(5 digits). 我有以下代码:

placeholder = "Long: %10s  Lat: %10s";
formatted = placeholder.format( longitude,  latitude);
mDataFeed=formatted+"\n"+mDataFeed;

输出为 long: 877678888,没有纬度,字符串长于 10 个字符。

这是完整的代码块

@Override  
public void onLocationChanged(Location loc) {  
    String longitude = "Long: " +loc.getLongitude(); 
    viewLog.setText(longitude);  
    String latitude = "Lat: " +loc.getLatitude(); 
    viewLat.setText( latitude); 
    pb.setVisibility(View.INVISIBLE); 

    String send=new String();
    send=longitude+" "+latitude+"\n";
    //   mDataFeed=send+mDataFeed;

    String placeholder = new String();
    String  formatted  = new String();

    placeholder = "Long: %10s  Lat: %10s";
    formatted = placeholder.format( longitude,  latitude);
    mDataFeed=formatted+"\n"+mDataFeed;
}  
4

1 回答 1

0

尝试更换

formatted = placeholder.format( longitude,  latitude);

formatted = placeholder.format( loc.getLongitude().toString(),  loc.getLatitude().toString());

或交替

placeholder = "Long: %10d  Lat: %10d";
formatted = placeholder.format( loc.getLongitude(),  loc.getLatitude());
于 2012-10-11T17:35:58.680 回答