HI all,
To find my current location i tried the below code but not working can
any one please help me what i did wrong or where i need to change
In AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"
/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
>From Activity on create im calling setLocation() method , it calling that
method then it printing the log of setLocation 1,setLocation 2A4 it even
not calling onStatusChanged, onlocationchange, it only calling
onProviderEnabled() so help me please.
private void setLocation() {
Log.e("setLocation", "setLocation 1");
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new mylocationlistener();
Log.e("setLocation", "setLocation 2A4");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, locationListener);
if (lat == 0.0) {
Log.e("setLocation", "getLastKnownLocation");
Location location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
makeUseOfNewLocation(location);
}
}
private class mylocationlistener implements LocationListener {
public void onLocationChanged(Location location) {
if (location != null) {
Log.e("inside onlocation change", "inside onlocation
chang");
lat = location.getLatitude() * 1E6;
lng = location.getLongitude() * 1E6;
}
}
public void onProviderDisabled(String provider) {
Log.e("onProviderDisabled", "1");
}
public void onProviderEnabled(String provider) {
Log.e("onProviderEnabled", "2");
}
public void onStatusChanged(String provider, int status, Bundle
extras) {
Log.e("onStatusChanged", "="+status);
}
}
protected void makeUseOfNewLocation(Location location) {
Log.e("setLocation", "setLocation 3");
if (location != null) {
Log.e("setLocation", "success");
lat = location.getLatitude();
lng = location.getLongitude();
Log.e("lat", "" + lat);
Log.e("lng", "" + lng);
}
}
--
Regards,
Perumal.N
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en