do not get the current location

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

do not get the current location

Postby reza » Sat Jan 22, 2011 12:37 am

hi...
I have been trying to get my current location but fail to get it.
I am using wifi. I tried
geo fix -77.036519 38.896143. but still its not working.
Here is my code:

Code: Select all
public class whereAmI extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        LocationManager locationManager;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(context);
        String provider = LocationManager.GPS_PROVIDER;
        Location location = locationManager.getLastKnownLocation(provider);
        updateWithNewLocation(location);
       
    }
    private void updateWithNewLocation(Location location) {
       String latLongString;
       TextView myLocationText;
       myLocationText = (TextView)findViewById(R.id.myLocationText);
       if (location != null) {
       double lat = location.getLatitude();
       double lng = location.getLongitude();
       latLongString = "Lat:" + lat + "\nLong:" + lng;
       } else {
       latLongString = "No location found";
       }
       myLocationText.setText("Your Current Position is:\n" +
       latLongString);
    }
}

I think its the problem with my emulator but not sure. Can anybody please help me to fix this thing..!!
reza
Freshman
Freshman
 
Posts: 9
Joined: Sat Jan 22, 2011 12:29 am

Top

Re: do not get the current location

Postby JoxTraex » Sat Jan 29, 2011 3:30 am

Code: Select all
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);


This already says that you are NOT using WIFI to get your location...

Some useful info about the LocationManager class:

public static final String NETWORK_PROVIDER

Since: API Level 1
Name of the network location provider. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
Constant Value: "network"


Source: http://developer.android.com/reference/ ... nager.html
JoxTraex
Developer
Developer
 
Posts: 25
Joined: Wed Jan 26, 2011 12:29 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 14 guests