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

  • SEARCH
  • Home
  • 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 6579615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:55:15+00:00 2026-05-25T15:55:15+00:00

I have GetURL method defined to find my location from network provider, you can

  • 0

I have GetURL method defined to find my location from network provider, you can send the code below.

If I define that code piece in my main class with Activity this works nicely but when I would like to create a seperate class (for instance GetLocation class), I cannot use getSystemService method and I receive error in subject (getSystemService is undefined for the type for GetLocation). There are couple of entries regarding this topic but I don’t understand fully.

That’s a rookie question so take this into account while answering 🙂 Thanks guys.

public String GetURL () {
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String locationProvider = LocationManager.NETWORK_PROVIDER;
    mostRecentLocation = locationManager.getLastKnownLocation(locationProvider);
    if(mostRecentLocation != null) {
        double lat = mostRecentLocation.getLatitude();
        double lng = mostRecentLocation.getLongitude();
        currentLocation = "Lat: " + lat + " Lng: " + lng;
        Log.e("LOCATION -------------", currentLocation + "");
    }
    return currentLocation;
}
  • 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-05-25T15:55:15+00:00Added an answer on May 25, 2026 at 3:55 pm

    The method getSystemService() belongs to the Context class.

    Therefore if you want to move getUrl() to become a utility method elsewhere, you need to pass in a Context object, such as the current Activity (as it inherits from Context).

    For example:
    Util.java

    public static String getUrl(Context context) {
        LocationManager lm = (LocationManager) 
            context.getSystemService(Context.LOCATION_SERVICE);
    
        // ... your existing code ...
        return currentLocation;
    }
    

    MyActivity.java

    public void onCreate() {
        // ... usual stuff ...
    
        String url = getUrl(this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with xhr open() method. My code follows : var xmlhttp=false; if(!xmlhttp)
I have this action script that pulls images from a xml file > myPhoto
I currently have code for posting data to a login page that works fine.
I have a HTTP class that gets content from URL's, POST's content to URL's
I have written something like this pretty easily in C# ( string GetUrl(new {
I have a constructor signature like this public NavigationLink(Func<String> getName, Func<UrlHelper, String> getURL, Func<bool>
Have you guys had any experiences (positive or negative) by placing your source code/solution
I'm looking to the best way to overriding the _get_url method from ImageField, I
All, I'm working on a Flash application that's supposed to send XML data to
I have found this example Lazy load of images in ListView from Fedor which

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.