以下のプログラムを試しました。日食で動作しています-> ddmsを介して緯度と経度の値を指定すると、エミュレーターに現在の位置として表示されます....しかし、Androidフォンで現在の位置を検出しません。
private class mylocationlistener implements LocationListener {
public void onLocationChanged(Location location) {
Date today = new Date();
Timestamp currentTimeStamp = new Timestamp(today.getTime());
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (isGPS){
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
if (location != null) {
Log.d("LOCATION CHANGED", location.getLatitude() + "");
Log.d("LOCATION CHANGED", location.getLongitude() + "");
String str = "\n CurrentLocation: "+
"\n Latitude: "+ location.getLatitude() +
"\n Longitude: " + location.getLongitude() +
"\n Accuracy: " + location.getAccuracy() +
"\n CurrentTimeStamp "+ currentTimeStamp;
Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();
tv.append(str);
}
else
{
String s1="GPS activation in process";
Toast.makeText(MainActivity.this,s1,Toast.LENGTH_SHORT).show();
/*alert.setTitle("gps");
alert.setMessage("GPS activation in progress,\n Please click after few second.");
alert.setPositiveButton("OK", null);
alert.show();*/
}
}
else
{
String s2="Enable Gps";
Toast.makeText(MainActivity.this,s2,Toast.LENGTH_SHORT).show();
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}