【问题标题】:how to get cell tower location in android如何在android中获取手机信号塔的位置
【发布时间】:2012-03-09 07:15:30
【问题描述】:

我想找到最近的手机信号塔位置。我试过了

private class ServiceStateHandler extends Handler {
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MY_NOTIFICATION_ID:
                ServiceState state = mPhoneStateReceiver.getServiceState();
                System.out.println(state.getCid());
                System.out.println(state.getLac());
                System.out.println(mPhoneStateReceiver.getSignalStrength());
                break;
        }
    }
}

我试过这个链接,但它不适合我How to find user location using cell tower?

我认为我做错了什么。因为此链接答案对其他人有用 我做了与链接中所示相同的代码 我正在使用 2,2 google api 创建项目 但我无法获得手机信号塔的位置

【问题讨论】:

标签: android


【解决方案1】:

查看这个网站,它解释得很好,也很简单:https://www.mylnikov.org/archives/1059

这是一个例子:

.MCC: 268
. MNC: 06
.LAC: 8280
.CELL ID: 5616

API 链接:https://api.mylnikov.org/geolocation/cell?v=1.1&data=open&mcc=268&mnc=06&lac=8280&cellid=5616

希望对你有所帮助。

【讨论】:

    【解决方案2】:

    执行此操作的代码不会等待意图,而是在活动 onCreate 中获取对电话服务的引用,并且在显示时仅在需要时调用 getCellLocation()

    m_manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    
    GsmCellLocation loc = (GsmCellLocation)m_manager.getCellLocation();
    if (loc != null)
    {
        out.format("Location ");
        if (loc.getCid() == -1) {
            out.format("cid: unknown ");
        } else {
            out.format("cid: %08x ", loc.getCid());
        }
        if (loc.getLac() == -1) {
            out.format("lac: unknown\n");
        } else {
            out.format("lac: %08x\n", loc.getLac());
        }
    }
    

    在侦听 PhoneStateService 意图时,我还看到我们必须在 TelephonyManager 上调用 listen 并指定感兴趣的字段。在我的情况下是:

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "service start");
        m_manager.listen(m_listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CALL_STATE);
        return super.onStartCommand(intent, flags, startId);
    }
    

    您可能需要将LISTEN_CELL_LOCATION 添加到列表中。

    注意:您是否将 ACCESS_COARSE_LOCATION 权限添加到应用清单?如 PhoneStateListener 文档中所述,如果您没有获取信息的权限,某些字段将为空。

    【讨论】:

    • 我想找到手机信号塔的位置(地址)。我有 mcc mnc cell id 和 lac.. 你知道怎么找到吗?
    【解决方案3】:

    试试这个代码 -

    mPhoneStateReceiver = new PhoneStateIntentReceiver(this, new ServiceStateHandler());
    mPhoneStateReceiver.notifyServiceState(MY_NOTIFICATION_ID);
    mPhoneStateReceiver.notifyPhoneCallState(MY_NOTIFICATION_ID);
    mPhoneStateReceiver.notifySignalStrength(MY_NOTIFICATION_ID);
    mPhoneStateReceiver.registerIntent();
    
    private class ServiceStateHandler extends Handler {
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MY_NOTIFICATION_ID:
                ServiceState state = mPhoneStateReceiver.getServiceState();
                System.out.println(state.getCid());
                System.out.println(state.getLac());
                System.out.println(mPhoneStateReceiver.getSignalStrength());
                break;
        }
    }
    }
    

    来自StackOverflow的这个问题

    【讨论】:

    • 我试过这个,我在我的问题中提到了它。 phonestatereceiver 不工作
    猜你喜欢
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    相关资源
    最近更新 更多