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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:20:52+00:00 2026-06-18T05:20:52+00:00

I am trying to show my current location in map along with the address.

  • 0

I am trying to show my current location in map along with the address. Below code works fine but somehow i am not able to draw or point a circle around my current location.Any help would be appreciated.I am using the old API.

This is my main class.

    public class GMapsActivity extends MapActivity implements LocationListener { 

    private static final String TAG = "LocationActivity";
    private static GMapsActivity instance;
    private MapView mapView; 
    protected LocationManager locationManager;
    public Button retrieveLocationButton;
    Geocoder geocoder; 
    TextView locationText;
    Location location;
    MapController mapController;
    CountDownTimer locationtimer;

        //  private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
//  private static final long MINIMUM_TIME_BETWEEN_UPDATES = 9000; // in Milliseconds
//    MapOverlay mapOverlay = new MapOverlay();
    @Override        
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_gmaps);

        mapView = (MapView) findViewById(R.id.map_view);
        mapView.setBuiltInZoomControls(true);
        locationText = (TextView)this.findViewById(R.id.lblLocationInfo);
        mapController = mapView.getController();  
        mapController.setZoom(13);
        retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button);

    }
    public void showcurrentlocation(View view) {

        geocoder = new Geocoder(GMapsActivity.this);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        mapView.getOverlays().add(new CircleOverlay(this, location.getLatitude(),location.getLongitude(),325));  
        if (location != null) {     
            Log.d(TAG, location.toString());   
            this.onLocationChanged(location); //<6>  

            } 
        }



    @Override  
            public void onLocationChanged(Location location) {
            Log.d(TAG, "onLocationChanged with location " + location.toString());   
            String text = String.format("Lat:\t %f\nLong:\t %f\nAlt:\t %f\nBearing:\t %f", location.getLatitude(),location.getLongitude(), location.getAltitude(),
                    location.getBearing());
            this.locationText.setText(text);  

                    try {     
                        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); //<10> 
                        for (Address address : addresses) {    
                            this.locationText.append("\n" + address.getAddressLine(0));   
                            }          
                        int latitude = (int)(location.getLatitude() * 1000000);  
                        int longitude = (int)(location.getLongitude() * 1000000);  
                        GeoPoint point = new GeoPoint(latitude,longitude);    
                        mapController.animateTo(point); //<11> 


                    }
                    catch (IOException e) {  
                        Log.e("LocateMe", "Could not get Geocoder data", e);   
                        }

    }
                    @Override
                    public void onProviderDisabled(String provider) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onStatusChanged(String provider, int status,Bundle extras) {
                        // TODO Auto-generated method stub


                    }


//                  @Override  protected void onResume() { 
//                  LocationListener locationListener = new LocationListener(){
//                        super.onResume(); 
//                  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this); //<7> 
//                  }  
//              @Override  protected void onPause() { 
//                  super.onPause();   
//                  locationManager.removeUpdates(this); //<8>
//                      
//                  }


      @Override
        protected boolean isRouteDisplayed() {
           return false;

        }
}

Below is my circle class.

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.FloatMath;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class CircleOverlay extends Overlay {

    Context context;
    double mLat;
    double mLon;
    float mRadius;

    public CircleOverlay(Context _context, double _lat, double _lon, float radius ) {
        context = _context;
        mLat = _lat;
        mLon = _lon;
        mRadius = radius;

        }

    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow); 

        if(shadow) return; // Ignore the shadow layer

        Projection projection = mapView.getProjection();

        Point pt = new Point();

        GeoPoint geo = new GeoPoint((int) (mLat *1e6), (int)(mLon * 1e6));

        projection.toPixels(geo ,pt);
        float circleRadius = projection.metersToEquatorPixels(mRadius) * (1/ FloatMath.cos((float) Math.toRadians(mLat)));

        Paint innerCirclePaint;

        innerCirclePaint = new Paint();
        innerCirclePaint.setColor(Color.BLUE);
        innerCirclePaint.setAlpha(25);
        innerCirclePaint.setAntiAlias(true);

        innerCirclePaint.setStyle(Paint.Style.FILL);

        canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, innerCirclePaint);

    }

}
  • 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-18T05:20:53+00:00Added an answer on June 18, 2026 at 5:20 am

    From google example: hello-mapview

    Each time you add a new OverlayItem to the ArrayList, you must call populate() for the ItemizedOverlay, which will read each of the OverlayItem objects and prepare them to be drawn.

    public void showcurrentlocation(View view) {
    
        geocoder = new Geocoder(GMapsActivity.this);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        mapView.getOverlays().add(new CircleOverlay(this, location.getLatitude(),location.getLongitude(),325));  
        if (location != null) {     
            Log.d(TAG, location.toString());   
            this.onLocationChanged(location); //<6>  
        } 
        populate();
    

    }

    But I think you should use the MyLocationOverlay class for this MyLocationOverlay

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

Sidebar

Related Questions

I'm trying to get my current location and show it on a map. Class
in my app i am trying to show the current location in a map.
I am trying to getting location or want to show location on map by
I am trying to show the user's current location and allowing user to place
I'm trying to get an MKMapView show my current location. I managed to get
I am trying to implement the map showing the current location with the path.
I am trying to show the users current location with the default blue dot
trying to find the current location of my device.code is here. package com.example.location; import
I am trying to get my own location.Below is the code which is giving
I am trying to get an Current Altitude from location.getAltitude() method. but it always

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.