Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:28:27+00:00 2026-06-13T20:28:27+00:00

Seems their were some updates to methods in this area as many existing examples

  • 0

Seems their were some updates to methods in this area as many existing examples do not work right…

Can someone show me how to get the name of the city from the network w/o gps and toast to screen?

It would be MUCH appreciated.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:28:28+00:00Added an answer on June 13, 2026 at 8:28 pm

    Get the latitude and longitude using NETWORK_PROVIDER, which won’t use GPS.
    Here is a Locator utility class I wrote for my purposes, you are welcome to use and it modify it. It is working and tested in an app with minSdk of 7.

    package com.emil;
    
    import android.content.Context;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    
    /**
     * For determining location of user using various methods
     * 
     * @author Emil http://stackoverflow.com/users/220710/emil
     *
     */
    public class Locator implements LocationListener {
    
        static private final int TIME_INTERVAL = 100; // minimum time betweeen updates in milliseconds
        static private final int DISTANCE_INTERVAL = 1; // minimum distance between updates in meters
    
        static public enum Method {
            NETWORK,
            GPS,
            NETWORK_THEN_GPS
        }
    
        private Context context;
        private LocationManager locationManager;
        private Locator.Method method;
        private Locator.Listener callback;
    
        public Locator(Context context) {
            super();
            this.context = context;
            this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        }
    
        public void getLocation(Locator.Method method, Locator.Listener callback){
            this.method = method;
            this.callback = callback;
            switch(this.method){
            case NETWORK:
            case NETWORK_THEN_GPS:
                Location networkLocation = this.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                if(networkLocation != null){
                    this.callback.onLocationFound(networkLocation);
                }else{
                    System.out.println("REQUEST UPDATES to NETWORK PROVIDER");
                    this.requestUpdates(LocationManager.NETWORK_PROVIDER);
                }
                break;
            case GPS:
                Location gpsLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                if(gpsLocation != null){
                    this.callback.onLocationFound(gpsLocation);
                }else{
                    System.out.println("REQUEST UPDATES to GPS PROVIDER");
                    this.requestUpdates(LocationManager.GPS_PROVIDER);
                }
                break;
            }
        }
    
        private void requestUpdates(String provider){
            if(this.locationManager.isProviderEnabled(provider)){
                if(provider.contentEquals(LocationManager.NETWORK_PROVIDER) 
                        && Connectivity.isConnected(this.context)){
                    System.out.println("NETWORK CONNECTED, START LISTENING: "+provider);
                    this.locationManager.requestLocationUpdates(provider, TIME_INTERVAL, DISTANCE_INTERVAL, this);
                }else if(provider.contentEquals(LocationManager.GPS_PROVIDER) 
                        && Connectivity.isConnectedMobile(this.context)){
                    System.out.println("MOBILE NETWORK CONNECTED, START LISTENING: "+provider);
                    this.locationManager.requestLocationUpdates(provider, TIME_INTERVAL, DISTANCE_INTERVAL, this);
                }else{
                    System.out.println("PROPER NETWORK NOT CONNECTED : "+provider);
                    this.onProviderDisabled(provider);
                }
            }else{
                this.onProviderDisabled(provider);
            }
        }
    
        public void cancel(){
            this.locationManager.removeUpdates(this);
        }
    
        @Override
        public void onLocationChanged(Location location) {
            System.out.println("LOCATION FOUND : "+location.getLatitude()+", "+location.getLongitude()+(location.hasAccuracy() ? " : +- "+location.getAccuracy()+" meters" : ""));
            this.locationManager.removeUpdates(this);
            this.callback.onLocationFound(location);
        }
        @Override
        public void onProviderDisabled(String provider) {
            System.out.println("PROVIDER DISABLED : "+provider);
            if( this.method == Locator.Method.NETWORK_THEN_GPS 
                    && provider.contentEquals(LocationManager.NETWORK_PROVIDER) ){
                // Network provider disabled, try GPS
                System.out.println("REQUEST UPDATES to GSP PROVIDER, NETWORK PROVIDER DISABLED");
                this.requestUpdates(LocationManager.GPS_PROVIDER);
            }else{
                this.locationManager.removeUpdates(this);
                this.callback.onLocationNotFound();
            }
        }
        @Override
        public void onProviderEnabled(String provider) {
            // empty
            System.out.println("PROVIDER ENABLED : "+provider);
        }
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // empty
            System.out.println("PROVIDER STATUS CHANGED : "+provider+" : STATUS : "+status);
    
        }
    
        public interface Listener {
            void onLocationFound(Location location);
            void onLocationNotFound();
        }
    
    }
    

    Make sure you add the appropriate permissions in your AndroidManifest.xml to use location providers.

    Then use an API from say Google Maps or something to convert to city name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at their help page it seems like I can register a
The discussion around global variables and their misuse seems to hold a certain dogmatic
Looking at the Android tutorial on: http://developer.android.com/guide/topics/fundamentals/fragments.html ... it seems fragments have their layouts
I am using their default POS tagging and default tokenization..and it seems sufficient. I'd
Twitter seems to be using an <i/> tag to display their icons from a
StackOverflow uses the GZip encoding on all of their pages; the same seems to
I installed Enthought's NumPy implementation for IronPython as per their instructions. Everything seems to
Seems to be a problem that many people have, but all the answers I
I've tried looking at other answers for this but I can't seem to figure
Im looking for methods to combine files including their name and relative path into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.