0

ネットワークプロバイダーのみを使用して、Android アプリで近くの都市を計算する必要があります。私は次のコードでそれを行うことができますが、アプリが非常に遅くなり、時々しか機能しません。



public Locator(final Context c) {

        LocationManager locationManager = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        Geocoder gcd = new Geocoder(c, Locale.getDefault());
        List addresses;
        try {
            addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
            if (addresses.size() > 0) {
                if(addresses.get(0).getLocality()!=null){
                    Locator.setCity(addresses.get(0).getLocality());
                }
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }       
    }

何か案は?

前もって感謝します。

4

1 に答える 1