Android之GPS-获得经纬度
2010-05-31 14:10:00 来源:WEB开发网核心提示:获取所在地的经纬度信息:代码如下:public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);LocationManager lm;Location l
获取所在地的经纬度信息:
代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm;
Location loc;
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
loc = lm.getLastKnownLocation(lm.GPS_PROVIDER); //获取location信息
if(loc != null){
double x,y;
x = loc.getLatitude(); //获取纬度
y = loc.getLongitude(); //获取经度
System.out.print(x);
System.out.println(y);
int i = (int) (loc.getLatitude() * 1E6);
int j = (int) (loc.getLongitude() * 1E6);
System.out.print(i+"~~~~");
System.out.println(-j); //我的所在地的经度为负值,我想输出的为正值,故取反
}
[]
更多精彩
赞助商链接