如何在Android的一个按钮,点击找到我的当前位置(latitute +经度)? [英] How to find my current location (latitute + longitude) on click of a button in android?
本文介绍了如何在Android的一个按钮,点击找到我的当前位置(latitute +经度)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我见过各种各样的code段找到它从出局的各种方法,如onlocationupdate()或onstatusChanged()......坐标我想要的是一个简单的code,它获取我目前的GPS合作上一个按钮,点击坐标...
解决方案
的LocationManager mLocManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的mLocListener =新MyLocationListener();
mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mLocListener);公共类MyLocationListener实现LocationListener的{ 公共无效onLocationChanged(位置LOC){
字符串消息=的String.format(
新位置\\ n经度:%1 $ S \\北纬:%2 $ S
location.getLongitude(),location.getLatitude()
);
Toast.makeText(LbsGeocodingActivity.this,消息,Toast.LENGTH_LONG).show();
}
公共无效onProviderDisabled(字符串为arg0){ }
公共无效onProviderEnabled(字符串提供商){ }
公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){ }
}
阅读详细<一个href=\"http://www.java$c$cgeeks.com/2010/09/android-location-based-services.html\">http://www.java$c$cgeeks.com/2010/09/android-location-based-services.html
I have seen various code snippets which find outs co-ordinates from various methods like onlocationupdate() or onstatusChanged().... what i want is a simple code that fetches my current GPS co-ordinates on click of a button...
解决方案
LocationManager mLocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mLocListener = new MyLocationListener();
mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener);
public class MyLocationListener implements LocationListener{
public void onLocationChanged(Location loc) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String arg0) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
Read this for detail http://www.javacodegeeks.com/2010/09/android-location-based-services.html
这篇关于如何在Android的一个按钮,点击找到我的当前位置(latitute +经度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文