2

I am following a tutorial to get my current location. I wrote exactly what the tutorial said, but i just do not get my lat/lon. I am using a wifi connection. I tried:
geo fix -77.036519 38.896143
still do not get the lat/lon. My code is as follows;

import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.TextView;

public class TestProviderController extends Activity {
 LocationManager locationManager;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String location_context=Context.LOCATION_SERVICE;
        locationManager=(LocationManager)getSystemService(location_context);
        testProvider();
    }
    public void testProvider(){
     TextView tv = (TextView)findViewById(R.id.myTextView);
     StringBuilder sb = new StringBuilder("Enabled Providers:");

     List<String> providers = locationManager.getProviders(true);

     for (String provider : providers) {

     locationManager.requestLocationUpdates(provider, 1000, 0,
     new LocationListener() {
     public void onLocationChanged(Location location) {}
     public void onProviderDisabled(String provider){}

     public void onProviderEnabled(String provider){}
     public void onStatusChanged(String provider, int status,
     Bundle extras){}
     });
     sb.append("\n").append(provider).append(":");
     Location location = locationManager.getLastKnownLocation(provider);
     if (location != null) {
     double lat = location.getLatitude();
     double lng = location.getLongitude();
     sb.append(lat).append(",").append(lng);
     } else {
     sb.append("No Location");
     }
     }
     tv.setText(sb);
    }
}

Can anybody please help about what went wrong?

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Reza.Hoque
  • 2,690
  • 10
  • 49
  • 78

1 Answers1

1

It can apparently take a little time to get the coordinates - here's a link to a similar question

Community
  • 1
  • 1
John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • Hi..I tried the link u suggested, still not getting my lat/lon. But as u said it may take some time, how long it can take to get the lat/lon?? – Reza.Hoque Jan 22 '11 at 13:48