开发者

Can't get android to write GeoPoint GPS coordinate data to a file correctly

开发者 https://www.devze.com 2023-02-11 07:17 出处:网络
Im currently writing some software for android that takes gps data in the form of an ArrayList of GeoPoints and writes it to a KML file. The rest of file is created fine, but when the gps data is writ

Im currently writing some software for android that takes gps data in the form of an ArrayList of GeoPoints and writes it to a KML file. The rest of file is created fine, but when the gps data is written to the file in the following way:

for(int i=0; i < geoPoints.size(); i++){    
    writer.write(geoPoints.get(i).getLatitudeE6());
    writer.write(", ");
    writer.write(geoPoints.get(i).getLongitudeE6());
    writer.write("\n");
}

The output of file is random characters:

ꗺ, 繿
ꔚ, 练
鬅, 眑

If I change the loop to convert it to a String:

for(int i=0; i < geoPoints.size(); i++){    
    writer.wri开发者_Python百科te(Integer.toString(geoPoints.get(i).getLatitudeE6()));
    writer.write(", ");
    writer.write(Integer.toString(geoPoints.get(i).getLongitudeE6()));
    writer.write("\n");
}

Then the output is almost correct, but there isn't a decimal place?

-45570790, 167608003
-45571713, 167608345
-45572973, 167606660

Can anyone help me find that pesky decimal?


E6 means its lat * 1E6, so for it to look like -45.57 vs -45570790 you need to divide by 1E6.

for(int i=0; i < geoPoints.size(); i++){    
    writer.write(Integer.toString(geoPoints.get(i).getLatitudeE6() / 1E6));
    writer.write(", ");
    writer.write(Integer.toString(geoPoints.get(i).getLongitudeE6() / 1E6));
    writer.write("\n");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消