Conversion to GeoPoint

2019-07-28 10:52发布

Hello I have the next strange problem: I recover the coordinates from a sql server as a double, I convert it to float and after that I convert to intE6. I set two prints, one before the conversion to GeoPoint and other after that. Well, the first seems that print good values but in the second, the value of longitude value fails.

There is the example:

float latitude = (float) json_data.getDouble("latitude");
float longitude = (float) json_data.getDouble("longitude");

Log.d("POINT",(int)(latitude*10E6)+" "+ (int)((longitude*10E6)));

GeoPoint p = new GeoPoint((int)(latitude*10E6), (int)(longitude*10E6));

Log.d("POINT", ""+p.getLatitudeE6()+" "+p.getLongitudeE6());

My values in server: -4.779396 , 37.878901

The printed values:

-4779360 378789024

-4779360 18789024

Thanks for your help!

1条回答
Lonely孤独者°
2楼-- · 2019-07-28 11:04

instead 10E6 use 1E6, so change code to following:

GeoPoint p = new GeoPoint((int)(latitude*1E6), (int)(longitude*1E6));

as 10E6 will result into the same number, as input, whereas 1E6 will multiply number by 10 raise to power 6.

查看更多
登录 后发表回答