Locating current position in android without GPS

后端 未结 3 1777
耶瑟儿~
耶瑟儿~ 2020-12-31 20:40

I want to develop an application in which, if i open the app, it will show current location of my device. I want to do it without using gps. I have write a code for it. But

3条回答
  •  悲&欢浪女
    2020-12-31 21:08

    I didn't find the LocationListener to be useful, but need to put it in anyway to prevent null pointers.

    // Set the criteria of what to look for
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    
    // This will find the location of the device via your network, but give user option to use GPS if needed
    String locationprovider = mlocManager.getBestProvider(criteria,
                true);
    
    mLoc = mlocManager.getLastKnownLocation(locationprovider);
    if (mLocation != null)
    {
        String Text = "My current location is: " +
        "Latitud = " + mLoc.getLatitude() +
        "Longitud = " + mLoc.getLongitude();
    } else
    {
        String Text = "No location found."
    }
    

提交回复
热议问题