Search Results

Search found 1 results on 1 pages for 'user1891806'.

Page 1/1 | 1 

  • Cant get a location

    - by user1891806
    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

    Read the article

1