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 8497001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:00:15+00:00 2026-06-11T00:00:15+00:00

I am working on a widget for Android, which displays your current location. To

  • 0

I am working on a widget for Android, which displays your current location. To get the current latitude and longitude I have the following code:

public class LocationInfo extends Activity {

RemoteViews remoteViews;

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationListener locationListener = new myLocationListener();
LocationProvider locationProvider = locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);

class myLocationListener implements LocationListener {

    public void onLocationChanged(Location location) {
        if(location != null)
        {
            double Long = location.getLongitude();
            double Lat = location.getLatitude();

            remoteViews.setTextViewText(R.id.widget_textview3, Double.toString(Long));
        }

        else {
            remoteViews.setTextViewText(R.id.widget_textview3, "LOADING...");
        }

    }

    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        // TODO Auto-generated method stub

    }
}
}

However, I get an error at the arguments of requestLocationUpdates. It says “Syntax error on tokens, VariableDeclarator expected instead” at 0,0, locationListener.

Also, this is a separate class. How would I then run this in my widget? Something like:

LocationInfo locationProvider = new LocationInfo();
LocationProvider.run();

maybe? Again, any help would really be appreciated!

  • 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-11T00:00:18+00:00Added an answer on June 11, 2026 at 12:00 am

    You are not allowed to execute

    locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);
    

    outside of methods.
    Just move in to, for example, onCreate of Activity.

    Good luck

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

Sidebar

Related Questions

I managed to get the YUI calendar widget working fine. But When it displays
I'm working on an Android widget that will show the current network state (i.e
I'm working on an Android widget which essentially places a button on the homescreen.
I'm working on an Android app which has an activity and a widget. This
I'm working on an android app which at a point uses a DatePicker widget,
I am developing an android app (only Widget) which displays some images from a
i have this code: import android.app.Activity; import android.app.ListActivity; import android.os.Bundle; import android.widget.AdapterView; import android.widget.ArrayAdapter;
I have the following code that is working but when I hit the hardware
I'm trying to get the dojo tree widget working. It works with a small
I made an app which is just working fine. It displays the number of

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.