Get Latitude and Longitude without inserting Sim Card and Start/Stop Gps from Application

后端 未结 4 616
生来不讨喜
生来不讨喜 2020-12-10 09:00

I am trying to fetch Gps latitude and longitude, but i am having a query that whenever i try to fetch Lat & Long without sim card, it is not providing any info where as

4条回答
  •  眼角桃花
    2020-12-10 10:01

    This might be outdated, but do you have any idea what the error is?

    I'm getting the error as, "error getting cell location info".

    I found the source code that lead to this error.

    private void requestRefLocation(int flags)
    {
        TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
        {
            GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
            if ((gsm_cell != null)
                    && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
                    && (phone.getNetworkOperator() != null)
                    && (phone.getNetworkOperator().length() > 3))
            {
                int type;
                int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
                int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
                int networkType = phone.getNetworkType();
                if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
                        || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
                        || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
                        || networkType == TelephonyManager.NETWORK_TYPE_HSPA)
                {
                    type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
                }
                else
                {
                    type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
                }
                native_agps_set_ref_location_cellid(type, mcc, mnc, gsm_cell.getLac(), gsm_cell.getCid());
            }
            else
            {
                Log.e(TAG, "Error getting cell location info.");
            }
        } else {
            Log.e(TAG, "CDMA not supported.");
        }
    }
    

    Notice the check statement

    if ((gsm_cell != null)
                && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
                && (phone.getNetworkOperator() != null)
                && (phone.getNetworkOperator().length() > 3))
        {
    

    It somehow leads to the problem you're facing. Of course, by connecting to a WIFI network, you will still get your location as it's using a different way to get it. I hope this answer your question.

提交回复
热议问题