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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:29:31+00:00 2026-05-27T00:29:31+00:00

It auto detect my current location when i run this app but there isn’t

  • 0

It auto detect my current location when i run this app but there isn’t any marker the point at my current location, may i know why? The rest are fine, i am able to pin point other locations as well as fetching the address back to the textbox. The only problem i am facing is the marker doesn’t appear at my current location when i first run this MAP. Why?

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);

        txtLocation = (EditText) this.findViewById(R.id.txtLocation);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mc = mapView.getController();

        List<Overlay> mapOverlays = mapView.getOverlays();
        MapOverlay mapOverlay = new MapOverlay();

        mapOverlays.add(mapOverlay);

        // obtain gps location
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locationListener = new MyLocationListener();

        lm.requestLocationUpdates(
        // LocationManager.GPS_PROVIDER,
                LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    }

    private class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location loc) {
            if (loc != null) {
                // Toast.makeText(
                // getBaseContext(),
                // "Location changed: Lat: " + loc.getLatitude()
                // + " Lng: " + loc.getLongitude(),
                // Toast.LENGTH_SHORT).show();
            }
            p = new GeoPoint((int) (loc.getLatitude() * 1E6),
                    (int) (loc.getLongitude() * 1E6));
            mc.animateTo(p);
            mc.setZoom(18);

            // Add a location marker
            MapOverlay mapOverlay = new MapOverlay();
            List<Overlay> listofOverlays = mapView.getOverlays();
            listofOverlays.clear();
            listofOverlays.add(mapOverlay);

            // invalidate() method forces the MapView to be redrawn
            mapView.invalidate();
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    class MapOverlay extends com.google.android.maps.Overlay {

        @Override
        public boolean onTap(final GeoPoint p, MapView mapView) {
            // TODO Auto-generated method stub

            k = p;
            mc = mapView.getController();
            mc.animateTo(p);

            mapView.invalidate();


            new AlertDialog.Builder(ShowMaps.this)
                    .setTitle("Change location..")
                    .setMessage("Go to the new location?")
                    .setNegativeButton("NO",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // TODO Auto-generated method stub
                                    dialog.dismiss();
                                }
                            })
                    .setPositiveButton("YES",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // TODO Auto-generated method stub
                                    Geocoder geoCoder = new Geocoder(
                                            getBaseContext(), Locale
                                                    .getDefault());
                                    try {
                                        List<Address> addresses = geoCoder.getFromLocation(
                                                p.getLatitudeE6() / 1E6,
                                                p.getLongitudeE6() / 1E6, 1);
                                        String add = "";
                                        if (addresses.size() > 0) {
                                            for (int i = 0; i < addresses
                                                    .get(0)
                                                    .getMaxAddressLineIndex(); i++)
                                                add += addresses.get(0)
                                                        .getAddressLine(i);

                                        }
                                        Booking.txtLocation.setText(add);
                                        finish();
                                        // Toast.makeText(getBaseContext(), add,
                                        // Toast.LENGTH_SHORT).show();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }).show();
            return true;
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                long when) {
            super.draw(canvas, mapView, shadow);
            if (k != null) {
                // ---translate the GeoPoint to screen pixels---
                Point screenPts = new Point();
                mapView.getProjection().toPixels(k, screenPts);

                // ---add the marker---
                Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                        R.drawable.marker);
                canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
            }
            return true;
        }
    }
}
  • 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-27T00:29:32+00:00Added an answer on May 27, 2026 at 12:29 am

    Considered doing following:

        mMyLocationOverlay = new MyLocationOverlay(this, mMapView);
        mMapView.getOverlays().add(mMyLocationOverlay);
    

    Your code for adding looks correct, maybe you don’t get your location back through the listener, tryed setting breakpoint to track down the error?

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

Sidebar

Related Questions

I'm trying to make some auto suggest stuff for an app. But i'm having
I am trying to detect when a new App is being installed but only
Can you auto detect a hyperlink in HTML,JavaScript or Objective C?
We use the following function to auto detect if we are on a machine
I am developing an auto-builder that will run a series of steps in our
I'm trying to auto-detect if the selection of a textarea contains new lines, or
I know wordpress,joomla,drupal etc ( most of php_mysql stack ) can auto detect update
How can I detect that application was automatically started (auto-start when device turned on)
When committing changes to Mercurial, it can auto-detect move/copy/renames by using the command hg
On the current project I am working on, there is, at the moment, a

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.