seetharam1000
Newbie
hi friends,
am looking to get the output for finding the coordinates of GPS, WiFi, and Networking, eventhough i got the output for all three, i am getting the same coordinates (same value) output for WiFi and Networking.
Help me friends.
am looking to get the output for finding the coordinates of GPS, WiFi, and Networking, eventhough i got the output for all three, i am getting the same coordinates (same value) output for WiFi and Networking.
Help me friends.
Code:
package com.gps;
import android.app.Activity;
import android.content.Context;
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;
import android.widget.Toast;
public class GpsActivity 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;
@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);
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
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
wifi();
networking();
}
});
}
protected void wifi() {
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
String londitude = " " + location.getLongitude();
String latitude = " " + location.getLatitude();
L2.setText(londitude);
L5.setText(latitude);
} else {
L2.setText("Enable Provider");
L5.setText("Enable Provider");
}
}
protected void networking() {
Criteria criteria = new Criteria();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
String londitude = " " + location.getLongitude();
String latitude = " " + location.getLatitude();
L3.setText(londitude);
L6.setText(latitude);
} else {
L3.setText("Enable Provider");
L6.setText("Enable Provider");
}
}
protected void Refresh() {
L1.setText(" ");
L2.setText(" ");
L3.setText(" ");
L4.setText(" ");
L5.setText(" ");
L6.setText(" ");
}
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
double Location = loc.getLatitude();
if (Location != 0) {
String londitude = " " + loc.getLongitude();
String latitude = " " + loc.getLatitude();
L1.setText(londitude);
L4.setText(latitude);
} else {
L1.setText("Enable Provider");
L4.setText("Enable Provider");
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}