I am developing a small Android application in which I want to find out the current location of a user using a network provider. I tried it as follows, but it did not give me a way out:
networklocationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener networklocationListener = new LocationListener() { public void onLocationChanged(Location location) { Log.i("********************************", "this is my network location " + location); String Location_text = "NETWORK LOCATION latitude:" + location.getLatitude() + " longitude:" + location.getLatitude(); network_location.setText(Location_text); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location // updates networklocationManager .requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networklocationListener);
I gave permissions in my manifest file like this
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Is there something I don't see? Is it correct? Help is needed. Thank...
public class MainActivity extends Activity implements LocationListener { private TextView latituteField; private TextView longitudeField; private LocationManager gpslocationManager; private LocationManager networklocationManager; private LocationManager networklocationManager1; private String provider; private TextView gps_location; private TextView network_location; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gps_location = (TextView) findViewById(R.id.gps_location); network_location = (TextView) findViewById(R.id.network_location); networkLocation(); } public void networkLocation() { networklocationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); LocationListener networklocationListener = new LocationListener() { public void onLocationChanged(Location location) { Log.i("********************************", "this is my network location " + location); String Location_text = "NETWORK LOCATION latitude:" + location.getLatitude() + " longitude:" + location.getLatitude(); network_location.setText(Location_text); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; networklocationManager .requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networklocationListener); } }
android geolocation
nilkash Apr 15 '13 at 11:06 on 2013-04-15 11:06
source share