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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:13:24+00:00 2026-06-06T03:13:24+00:00

This is the code i written to get the gps coordinates of the mobile

  • 0

This is the code i written to get the gps coordinates of the mobile and point the place where you are. But in improvement I need to get 1km radius circle. How can i get it?

package m.a.p;
public class MappingActivity extends MapActivity {    
    MapController mControl;
    GeoPoint GeoP;
    MapView mapV;
    Drawable d;
    List<Overlay> overlaylist;

    public double lat;
    public double lng;
    Button checkin, addplace;

    private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in
                                                                        // Meters
    private static final long MINIMUM_TIME_BETWEEN_UPDATES = 10000; // in
                                                                    // Milliseconds

    protected LocationManager locationManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapV = (MapView) findViewById(R.id.mapview);
        checkin = (Button) findViewById(R.id.check);
        addplace = (Button) findViewById(R.id.addp);

        overlaylist = mapV.getOverlays();

        d = getResources().getDrawable(R.drawable.point);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                MINIMUM_TIME_BETWEEN_UPDATES,
                MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener());

        Location location = locationManager
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location != null) {

            lat = location.getLatitude();
            lng = location.getLongitude();

        }

        Button check = (Button) findViewById(R.id.check);
        Button addplace = (Button) findViewById(R.id.addp);
        Button nearby = (Button) findViewById(R.id.point);

        check.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                TextView result = (TextView) findViewById(R.id.result);
                result.setText("Checked the Plce");
            }
        });
        addplace.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                TextView result = (TextView) findViewById(R.id.result);
                result.setText("Added the Plce");
            }
        });
        nearby.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                TextView result = (TextView) findViewById(R.id.result);
                result.setText("Nearby the Plce");
            }
        });

    }

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

    public class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location location) {
            String message = String.format("You are Here");

            Toast.makeText(MappingActivity.this, message, Toast.LENGTH_LONG)
                    .show();

            GeoP = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

            mControl = mapV.getController();
            mControl.animateTo(GeoP);
            mControl.setZoom(19);

            OverlayItem overlayItem = new OverlayItem(GeoP, "You are Here",
                    "Point");
            CustomPinpoint custom = new CustomPinpoint(d, MappingActivity.this);
            custom.insertPinpoint(overlayItem);
            overlaylist.add(custom);
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

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

custompinpoint
public class CustomPinpoint extends ItemizedOverlay{

    private ArrayList<OverlayItem> pinpoints = new ArrayList <OverlayItem>();
    private Context c;


    public CustomPinpoint(Drawable defaultMarker) {
        super(boundCenter(defaultMarker));
    }

    public CustomPinpoint(Drawable m, Context context){
        this(m);
        c = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return pinpoints.get(i);
    }

    @Override
    public int size() {
        return pinpoints.size();
    }

    public void insertPinpoint(OverlayItem item){
        pinpoints.add(item);
        this.populate();
    }

}
  • 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-06T03:13:26+00:00Added an answer on June 6, 2026 at 3:13 am

    Try to use a custom MapOverlay to draw your location and a circle around it whit overriding onDraw() method:

    public class MyOwnLocationOverlay extends MyLocationOverlay{
    
        private MapView mapView;
        private Paint circlePainter;
        private Point screenCurrentPoint;
        private GeoPoint geoCurrentPoint;
        private int meters;
    
        public MyOwnLocationOverlay(Context context, MapView mapView) {
            super(context, mapView);
            this.mapView = mapView;
        }
    
        // This method is used to get user submitted radius from our application
        public void setMeters(int meters) {
            this.meters = meters;
        }
    
        @Override
        public synchronized boolean draw(Canvas canvas, MapView mapView,
                boolean shadow, long when) {
            // Set the painter to paint our circle. setColor = blue, setAlpha = 70 so the background
            // can still be seen. Feel free to change these settings
            circlePainter = new Paint();
            circlePainter.setAntiAlias(true);
            circlePainter.setStrokeWidth(2.0f);
            circlePainter.setColor(0xff6666ff);
            circlePainter.setStyle(Style.FILL_AND_STROKE);
            circlePainter.setAlpha(70);
    
            // Get projection from the mapView. 
            Projection projection = mapView.getProjection();
            // Get current location
            geoCurrentPoint = getMyLocation();
            screenCurrentPoint = new Point();
            // Project the gps coordinate to screen coordinate
            projection.toPixels(geoCurrentPoint, screenCurrentPoint);
    
            int radius = metersToRadius(geoCurrentPoint.getLatitudeE6() /1000000);
            // draw the blue circle
            canvas.drawCircle(screenCurrentPoint.x, screenCurrentPoint.y, radius, circlePainter);
            return super.draw(canvas, mapView, shadow, when);
        }
    
        // hack to get more accurate radius, because the accuracy is changing as the location
        // getting further away from the equator
        public int metersToRadius(double latitude) {
            return (int) (mapView.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
        }
    }
    

    see this link for more details

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

Sidebar

Related Questions

I need to call a method from a webservice, so I've written this code:
Hi I have written this code that with output you can get that .remove()
I have written this code to make a binary file of float numbers, but
I've written this code that display the current time, but my problem is it
I have written this code to fire a http request through a proxy. But
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I've written this code to try and send a url as a post value
I have written this code to join ArrayList elements: Can it be optimized more?
I have written this code to convert string in such format 0(532) 222 22
I've written this code to show a prompt before a form is submitted. If

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.