public class MyLocation {
Context mContext;
LocationManager mlocManager;
LocationListener mlocListener;
double lat=0,lng=0;
public MyLocation(Context mContext) {
super();
this.mContext = mContext;
mlocManager = (LocationManager)mContext.getSystemService(mContext.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener {
private static final int TWO_MINUTES = 1000 * 60 * 2;
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +"Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude();
// Toast.makeText( mContext,Text,Toast.LENGTH_SHORT).show();
lat = loc.getLatitude();
lng = loc.getLongitude();
}
public void onProviderDisabled(String provider){
Toast.makeText(mContext,"Gps Disabled",Toast.LENGTH_SHORT ).show();
}
public void onProviderEnabled(String provider){
Toast.makeText( mContext," Gps Enabled" ,Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
这个类没有返回它应该是什么......我的位置总是0.0 0.0
不知道该怎么做。
我像这样使用这个类
mylocation = new MyLocation(this);
我启动应用程序时启用了 gps 和网络,所以这不是问题...