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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:11:45+00:00 2026-06-07T04:11:45+00:00

I have the following onCreate() in my Android app: public void onCreate(Bundle savedInstanceState) {

  • 0

I have the following onCreate() in my Android app:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.customer_map);

        context=getApplicationContext();

        mapView = (MapView) findViewById(R.id.map);
        mapView.setBuiltInZoomControls(true);
        mapView.setEnabled(true);
        mapOverlays = mapView.getOverlays();


        //set my location marker
        myLocationOverlay = new MyLocationOverlay(context, mapView);
        myLocationOverlay.disableCompass();
        myLocationOverlay.enableMyLocation();
        mapOverlays.add(myLocationOverlay);

        myLocationOverlay.runOnFirstFix(new Runnable() {
            public void run() {
                mapView.getController().animateTo(myLocationOverlay.getMyLocation());
            }
        });



        //and zoom to current location
        MapController mc=mapView.getController();
        GeoPoint centre=new GeoPoint((int)(getBestLocation().getLat()*1e6),(int)(getBestLocation().getLng()*1e6));
        mc.setCenter(centre);
        mc.animateTo(centre);
        mc.setZoom(12);
    }

As you can see, I’m trying to display the current location. But it simply will not work! I think I’m doing something silly, but I can’t figure it out for the last hour.

Any insight greatly appreciated. Many thanks in advance,

p.s. here is getBestLocation:

private Coords getBestLocation() {
        Coords returnCoords=new Coords();

        Criteria criteria=new Criteria();
        //criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAccuracy(Criteria.POWER_LOW);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);


        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        String provider=lm.getBestProvider(criteria, true);
        if(provider!=null){
            lm.requestLocationUpdates(provider, 2000, 1, this);
            List<String> providers = lm.getProviders(false);
            //Loop over the array backwards, and if you get an accurate location, then break out the loop
            Location l = null;
            for (int i=providers.size()-1; i>=0; i--) {
                l = lm.getLastKnownLocation(providers.get(i));
                if (l != null ){
                    returnCoords.setLat(l.getLatitude());
                    returnCoords.setLng(l.getLongitude());
                    break;
                    //Log.i("EOH",String.valueOf(l.getLatitude()));
                }
            }
        }else{
            Toast.makeText(context, "Location not available", 3000).show();
        }
        return returnCoords;
    }
  • 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-07T04:11:46+00:00Added an answer on June 7, 2026 at 4:11 am

    Ok, it’s working now. Stupidly, I was doing this:

    @Override
        protected void onPause() {
            super.onPause();
            if(myLocationOverlay!=null){
                myLocationOverlay.disableMyLocation();
                myLocationOverlay.disableCompass();
            }
        }
        @Override
        protected void onResume() {
            super.onResume();
            if(myLocationOverlay!=null){
                **myLocationOverlay.disableLocation();**
                myLocationOverlay.disableCompass();
            }
        }
    

    I’m some clutz!

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

Sidebar

Related Questions

I have created following activity package com.ali.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import
I have the following activity... package org.dewsworld; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import
I have the following layout in XML (splashscreen.xml): <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/frmLayout
I have the following code in android - I'm using asmack API. public XMPPManager(String
I have a simple html/javascript based Android app that loads with the following code:
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following question on adobe omniture How we can register an iPhone app
Android:How to display images from the web in a ListView?I have the following code
I'm creating android app that has table layout for the main activity, and that
Top of my code package com.br.openeed.engtoolspro; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle;

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.