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

  • Home
  • SEARCH
  • 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 7171997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:31:30+00:00 2026-05-28T15:31:30+00:00

I made a map with the help of a map view.My map is working

  • 0

I made a map with the help of a map view.My map is working and also it allows me me to make a screenshot of the maap.But I am not able to locate my current location.i dont knw why my code is shown here.can anyone tell me how can i locate my current location.

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

        locationListener = new GPSLocationListener();


        locationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 
            0, 
            0, 
            locationListener);

//        Location intial = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
//        GeoPoint mainone=new GeoPoint((int) (intial.getLatitude() * 1E6), 
//                (int) (intial.getLongitude() * 1E6));
//        
//        mapController.animateTo(mainone);

        mapView = (MapView) findViewById(R.id.mapView);
        capture=(Button) findViewById(R.id.bcapture);

        capture.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
            getMapImage();
            saveMapImage();

            }
        });

        // enable Street view by default
        mapView.setStreetView(false);

        // enable to show Satellite view
        // mapView.setSatellite(true);

        // enable to show Traffic on map
        // mapView.setTraffic(true);
        mapView.setBuiltInZoomControls(true);

        mapController = mapView.getController();
//        mapController.setZoom(16); 
    }
    private Bitmap getMapImage() {  
        /* Position map for output */  
        MapController mc = mapView.getController();  
//        mc.setCenter(SOME_POINT);  
//        mc.setZoom(16);  

        /* Capture drawing cache as bitmap */  
        mapView.setDrawingCacheEnabled(true);  
        Bitmap bmp = Bitmap.createBitmap(mapView.getDrawingCache());  
        mapView.setDrawingCacheEnabled(false);  

        return bmp;  
    }  

    private void saveMapImage() {  
        String filename = "foo.png";  
        File f = new File("/sdcard/", filename);  
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(f);
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }  

        Bitmap bmp = getMapImage();  

        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);  

        try {
            out.close();
        } catch (IOException e) {

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

    private class GPSLocationListener implements LocationListener 
    {

        @Override
        public void onLocationChanged(Location location) {
            Location location1 = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (location1 != null) {

                GeoPoint point = new GeoPoint(
                        (int) (location1.getLatitude() * 1E6), 
                        (int) (location1.getLongitude() * 1E6));

                /* Toast.makeText(getBaseContext(), 
                        "Latitude: " + location.getLatitude() + 
                        " Longitude: " + location.getLongitude(), 
                        Toast.LENGTH_SHORT).show();*/
                   System.out.println(point.getLatitudeE6()+point.getLongitudeE6()+"helooooooo");
                   System.out.println(point.getLatitudeE6()+"buhahahooo");
                mapController.animateTo(point);
//                mapController.setZoom(16);

                // add marker
                MapOverlay mapOverlay = new MapOverlay();
                mapOverlay.setPointToDraw(point);
                List<Overlay> listOfOverlays = mapView.getOverlays();
                listOfOverlays.clear();
                listOfOverlays.add(mapOverlay);

                String address = ConvertPointToLocation(point);
                Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

                mapView.invalidate();
            }
        }

        public String ConvertPointToLocation(GeoPoint point) {   
            String address = "";
            Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                    point.getLatitudeE6()  / 1E6, 
                    point.getLongitudeE6() / 1E6, 1);

                if (addresses.size() > 0) {
                    for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
                        address += addresses.get(0).getAddressLine(index) + " ";
                }
            }
            catch (IOException e) {                
                e.printStackTrace();
            }   

            return address;
        } 

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

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

    class MapOverlay extends Overlay
    {
        private GeoPoint pointToDraw;

        public void setPointToDraw(GeoPoint point) {
            pointToDraw = point;
        }

        public GeoPoint getPointToDraw(
                ) {
            return pointToDraw;
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            super.draw(canvas, mapView, shadow);                   

            // convert point to pixels
            Point screenPts = new Point();
            mapView.getProjection().toPixels(pointToDraw, screenPts);

            // add marker
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); // 24 is the height of image        
            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-28T15:31:31+00:00Added an answer on May 28, 2026 at 3:31 pm

    Try to use object of MyLocationOverlay class

    MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this,mapView);
    mapView.getOverlays().add(myLocationOverlay);
    myLocationOverLay.enableMyLocation();
    myLocationOverlay.runOnFirstFix(new Runnable(){
       public void run(){
          mapView.getController().animateTo(myLocationOverlay.getMyLocation());
       }
    });
    

    this will solve your problem

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

Sidebar

Related Questions

I have made a application in android with map view and I want to
I have made a map with jQuery which is split up in many regions,
I made a view to abstract columns of different tables and pre-filter and pre-sort
I need to convert map coordinates into pixels (in order to make a clickable
I need to display an MKOverlay on a map, but can't get it to
I have a query that I have made into a MYSQL view. This particular
I made a simple map, and loaded all my points from a xml file,
instead of it displaying google map it only display grid view. -> i followed
If you ever played the original startcraft and selected an official map made by
I made this function and need some help sorting out the logic flow. It

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.