Cant get a location

Posted by user1891806 on Stack Overflow See other posts from Stack Overflow or by user1891806
Published on 2012-12-11T17:02:40Z Indexed on 2012/12/11 17:03 UTC
Read the original article Hit count: 371

Filed under:
|

Iam trying to get a location (latitute and longitude), I cant figure out what Im doing wrong but my location keeps returning null.

Anybody knows what I am doing wrong?

public class ParseJSON extends Activity implements LocationListener {

private TextView latituteField;
private TextView longitudeField;
LocationManager lm;
String provider;
int lat;
int lon;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();

    provider = lm.getBestProvider(crit, false);
    Location location = lm.getLastKnownLocation(provider);

    if (location != null){
        lat = (int) location.getLatitude();
        lon = (int) location.getLongitude();

        latituteField = (TextView) findViewById(R.id.lattest);
        longitudeField = (TextView) findViewById(R.id.lontest);

        latituteField.setText(lat);
        longitudeField.setText(String.valueOf(lon));


    }

    else {
        Toast.makeText(ParseJSON.this, "Couldnt get location", Toast.LENGTH_SHORT);
    }

    String readWeatherFeed = readWeatherFeed();
    try {
        JSONArray jsonArray = new JSONArray(readWeatherFeed);
        Log.i(ParseJSON.class.getName(),
                "Number of entries " + jsonArray.length());
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Log.i(ParseJSON.class.getName(), jsonObject.getString("text"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I dont have a clue, thanks in advance

© Stack Overflow or respective owner

Related posts about android

Related posts about location