【问题标题】:Android get location from cell towerAndroid从手机信号塔获取位置
【发布时间】:2013-09-19 07:01:32
【问题描述】:

您好,我想在没有互联网的情况下从手机信号塔(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();  
    }  
}  

【问题讨论】:

  • 上次我检查位置网络提供商需要互联网访问!
  • @LazyNinja 所以没有互联网我们无法获得位置?我认为手机信号塔返回位置,所以我正在尝试
  • 您可以使用 GPS 提供商!这是我知道的唯一其他方式。但 GPS 无法从手机信号塔获取位置。
  • 但是 GPS 也可以从互联网上获取位置。我想以任何方式没有互联网。
  • 据我了解,无需互联网即可获取 GPS 位置。如果 onLocationChanged() 没有触发,可能是因为您正在建筑物内进行测试。要对其进行测试,请将其放在设备上并走到外面。

标签: android android-location android-loadermanager


【解决方案1】:

蜂窝地理定位通过将蜂窝塔 ID 发送到将其映射到坐标的服务器来工作。因此,很遗憾,您无法通过标准 API 获得无数据连接的坐标。

【讨论】:

    猜你喜欢
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    相关资源
    最近更新 更多