seetharam1000
Newbie
hi
i try to find the x and y co-ordinates through gps, wifi, and networking but i have problem in running the problem, at output it shows FORCE TO CLOSE error, then i paste the log cat error, as below, can you help.
i try to find the x and y co-ordinates through gps, wifi, and networking but i have problem in running the problem, at output it shows FORCE TO CLOSE error, then i paste the log cat error, as below, can you help.
Code:
package com.location;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class LocationIdentifierActivity extends Activity {
/** Called when the activity is first created. */
TextView L1, L2, L3, L4, L5, L6;
Button B1;
Button button2;
LocationManager locationManager;
String provider;
LocationListener locListener;
private boolean gps_enabled = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
B1=(Button)findViewById(R.id.button1);
button2=(Button)findViewById(R.id.button2);
L1 = (TextView) findViewById(R.id.lat1);
L2 = (TextView) findViewById(R.id.lat2);
L3 = (TextView) findViewById(R.id.lat3);
L4 = (TextView) findViewById(R.id.long1);
L5 = (TextView) findViewById(R.id.long2);
L6 = (TextView) findViewById(R.id.long3);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
B1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Refresh();
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
gps();
wifi();
networking();
}
});
}
protected void gps() {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locListener);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String londitude = "Londitude: " + location.getLongitude();
String latitude = "Latitude: " + location.getLatitude();
L1.setText(londitude);
L4.setText(latitude);
} else {
L1.setText("Enable Provider");
L4.setText("Enable Provider");
}
}
protected void wifi() {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locListener);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String londitude = "Londitude: " + location.getLongitude();
String latitude = "Latitude: " + location.getLatitude();
L1.setText(londitude);
L4.setText(latitude);
} else {
L1.setText("Enable Provider");
L4.setText("Enable Provider");
}
}
protected void networking() {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locListener);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String londitude = "Londitude: " + location.getLongitude();
String latitude = "Latitude: " + location.getLatitude();
L1.setText(londitude);
L4.setText(latitude);
} else {
L1.setText("Enable Provider");
L4.setText("Enable Provider");
}
}
protected void Refresh() {
L1.setText(" ");
L2.setText(" ");
L3.setText(" ");
L4.setText(" ");
L5.setText(" ");
L6.setText(" ");
}
{
}
}