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
}
}
}
를 반환합니다.실제로 내 위치를 반환해야하고이 클래스는이 클래스가 ... 내 위치는 항상 <code>0.0 0.0</code> 무엇을 몰라해야 무엇을 반환하지 않습니다 0.0 0.0
내가
당신이 당신의 Manifest.xml에 올바른 사용 권한이 있습니까? – tolgap
사용자 위치를 가져올 권한을 추가 했습니까? http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION 및 http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION –
에뮬레이터를 사용하는 경우 이 기능을 테스트하려면 0.0, 0.0을 반환합니다. – Midhu