こんにちは、インターネットなしでセルタワー (SIM カード) から位置情報を取得したいです。ネットワークが利用可能なときに最後の場所のみを提供する以下のコードを使用しました。
私の要件は、WiFi またはインターネットなしで場所を取得することです。可能でしょうか?
package com.example.gpscelltower;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class CellTowerActivity1 extends Activity {
private static final String TAG = "Cell";
private static LocationManager locationManager;
private static LocationListener locationListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cell_tower);
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
String providerName=LocationManager.NETWORK_PROVIDER;
Location location=locationManager.getLastKnownLocation(providerName);
updateWithLocation(location);
//Cell-ID and WiFi location updates.
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d("TAG", "locationListner");
updateWithLocation(location);
String Text = "My current location is: " + "Latitude = "+ location.getLatitude() + "Longitude = " + location.getLongitude();
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_LONG).show();
Log.d("TAG", "Starting..");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("TAG", "onSatatus");
}
public void onProviderEnabled(String provider) {
Log.d("TAG", "onProviderEnable");
}
public void onProviderDisabled(String provider) {
Log.d("TAG", "onProviderDisble");
}
};
}
private void updateWithLocation(Location location) {
Log.d("TAG", "UpdateWithLocation");
String displayString;
if(location!=null){
Double lat=location.getLatitude();
Double lng=location.getLongitude();
Long calTime=location.getTime();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(calTime);
String time=formatter.format(calendar.getTime()).toString();
displayString="The Lat: "+lat.toString()+" \nAnd Long: "+lng.toString()+"\nThe time of Calculation: "+time;
}else{
displayString="No details Found";
}
Toast.makeText(CellTowerActivity1.this, ""+displayString, Toast.LENGTH_LONG).show();
}
}