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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:17:50+00:00 2026-06-01T14:17:50+00:00

I am using Google Maps for finding the location on a provided address. I

  • 0

I am using Google Maps for finding the location on a provided address.

I want to store the image of location which I get from Google Maps onClick.

Does anyone know how to do this?

Here is my code for google map & storing onClick

public class TestGPSActivity extends MapActivity 
 {    
MapView mapView;
private MapController mc;
private GeoPoint p;
private double lng;
private double lat;
private Address address;
private View mCurrentUrlMask;
private File imageFile; 

class MapOverlay extends com.google.android.maps.Overlay
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
            boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);

        //---add the marker---
        Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.pin);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
        return true;
    }
} 
public boolean onTouchEvent(MotionEvent event, MapView mapView) 
{   
    //---when user lifts his finger---
    if (event.getAction() == 1) {                
        GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());

        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) + "\n";
            }

            Toast.makeText(getBaseContext(), add, Toast.LENGTH_LONG).show();
        }
        catch (IOException e) {                
            e.printStackTrace();
        }   
        return true;
    }
    else                
        return false;
}             


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

    mapView = (MapView) findViewById(R.id.mapView); 

    mapView.setDrawingCacheEnabled(true);


     // image naming and path  to include sd card  appending name you choose for file
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + GPSActivity.DIRECTORY;   

    // create bitmap screen capture
    Bitmap bitmap;

    View v1 = mapView.getRootView();

    v1.setDrawingCacheEnabled(true);

    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    OutputStream fout = null;
    imageFile = new File(DemoCamGPSActivity.DIRECTORY);

    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("in file not found");
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
    View zoomView = mapView.getZoomControls();


    zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT)); 
    mapView.displayZoomControls(true);

    mc = mapView.getController();

    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    List<Address> addresses = null;
    try {   

        addresses = geocoder.getFromLocationName(getIntent().getStringExtra("address"), 1);

    } catch (IOException e) {



    }

    try{ 
        address = addresses.get(0);  
    }
    catch (Exception e) {
        flash("Unable to locate given address");
        startActivity(new Intent(this, GPSMainActivity.class));
        finish();
    }
    try{
      lng  = address.getLongitude();
      lat  = address.getLatitude();   

      GPSActivity.writeLog(getIntent().getStringExtra("address") +" GPS co-ordibnates : "+lat+" , "+lng);
    }catch (Exception e) {


    }


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

    mc.animateTo(p);
    mc.setZoom(17); 

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

    mapView.invalidate();
    mapView.invalidate();        
}
private void flash(String data) {   
    Toast.makeText(getApplicationContext(), data, Toast.LENGTH_LONG).show();
}


@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub    
    return false;
}

public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        startActivity(new Intent(this, GPSMainActivity.class));
        finish();
    }

    return super.onKeyDown(keyCode, event);
}    
 }

I am getting this error

03-28 16:54:12.580: E/AndroidRuntime(30010): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mentha.Demo/com.mentha.Demo.TestGPSActivity}: java.lang.NullPointerException

I am getting error on this perticular codes

   // create bitmap screen capture
    Bitmap bitmap;

    View v1 = mapView.getRootView();

    v1.setDrawingCacheEnabled(true);

    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    OutputStream fout = null;
    imageFile = new File(DemoCamGPSActivity.DIRECTORY);

    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("in file not found");
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    Uri uri = Uri.fromFile(new File(mPath));

Please help me out.. thanks in advance

  • 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-01T14:17:51+00:00Added an answer on June 1, 2026 at 2:17 pm

    I have solved this problem. I was having problem with image capturing of GPS location. I have just created the capture menu, In which after uploading the GPS location one can capture the image by clicking on capture menu button.

    Here is the whole code for capturing the screenshot of GPS location & how to find GPS location.

    public class TestGPSActivity extends MapActivity 
    {    
    MapView mapView;
    private MapController mc;
    private GeoPoint p;
    private double lng;
    private double lat;
    private Address address; 
    
    //google Map
    class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, 
                boolean shadow, long when) 
        {
            super.draw(canvas, mapView, shadow);                   
    
            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);
    
            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(
                    getResources(), R.drawable.pin);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }
    } 
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                    (int) event.getX(),
                    (int) event.getY());
    
            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) + "\n";
                }
    
                Toast.makeText(getBaseContext(), add, Toast.LENGTH_LONG).show();
            }
            catch (IOException e) {                
                e.printStackTrace();
            }   
            return true;
        }
        else                
            return false;
    }             
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps_main);
    
        mapView = (MapView) findViewById(R.id.mapView); 
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        View zoomView = mapView.getZoomControls(); 
    
        zoomLayout.addView(zoomView, 
                new LinearLayout.LayoutParams(
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);
    
        mc = mapView.getController();
    
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = null;
        try {   
    
            addresses = geocoder.getFromLocationName(getIntent().getStringExtra("address"), 1);
    
        } catch (IOException e) { 
            e.printStackTrace();
        }
    
        try{ 
            address = addresses.get(0);  
        }
        catch (Exception e) {
            flash("Unable to locate given address");
            startActivity(new Intent(this, GPSMainActivity.class));
            finish();
        }
        try{
            //stores the Longitude n lattitude in log file
            lng  = address.getLongitude();  
            lat  = address.getLatitude();   
    
            //for writing into log.text
            HomeActivity.writeLog(getIntent().getStringExtra("address") +" GPS co-ordibnates : "+lat+" , "+lng);
    
        }catch (Exception e) { 
            e.printStackTrace();
        } 
        p = new GeoPoint(
                (int) (lat * 1E6), 
                (int) (lng * 1E6));
    
        mc.animateTo(p);
        mc.setZoom(17); 
    
        //---Add a location marker---
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);        
    
        mapView.invalidate();
    
        //mapView.invalidate();      
    }   
    
    //ScreenShot of Image
    private void screenshot() {
        try{
            String mapDIR = HomeActivity.DIRECTORY+"/Image";
    
            File f = new File(mapDIR);
    
            if(! f.exists())
            {
                f.mkdir();
            }
    
            MapView v1 = (MapView)findViewById(R.id.mapView);
            v1.setDrawingCacheEnabled(true);
    
            Bitmap b = Bitmap.createBitmap(v1.getDrawingCache());
    
            try
            {
                FileOutputStream fos = new FileOutputStream(mapDIR+"/"+System.currentTimeMillis()+".png");
                b.compress(CompressFormat.PNG, 50, fos);
                fos.close();
    
            } catch (FileNotFoundException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(),Toast.LENGTH_LONG).show();
                e.printStackTrace();
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(),Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
            v1.setDrawingCacheEnabled(false); // clear drawing cache
        }catch (Exception e) {
            Toast.makeText(getApplicationContext(), e.getMessage(),Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    
    }
    
    private void flash(String data) {   
        Toast.makeText(getApplicationContext(), data, Toast.LENGTH_LONG).show();
    }
    
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub    
        return false;
    }
    
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if(keyCode == KeyEvent.KEYCODE_BACK)
        {
            startActivity(new Intent(this, GPSMainActivity.class));
            finish();
        } 
        return super.onKeyDown(keyCode, event);
    }     
    //menu button
    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) 
    {
        super.onCreateOptionsMenu(menu);
    
        menu.add(0, 1, 0 , "Exit");
        menu.add(0, 2, 0 , "Capture Image");
    
    
    
        return true;
    } 
    
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item)
    {
        switch(item.getItemId()) 
        {
        case 1: 
            startActivity(new Intent(this, GPSMainActivity.class));
            finish();
            break; 
        case 2: 
            screenshot();
            Toast.makeText(getApplicationContext(), "Captured Map", Toast.LENGTH_SHORT).show();
            break; 
        }
        return super.onMenuItemSelected(featureId, item);
    }
    }
    

    Thanks for All.. Hope this will help some one..

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

Sidebar

Related Questions

I have created an infobox using google maps api v3 and infoBox from the
I want to add some custom roads using google maps api (i.e. off-road routes,
It seems that licensing terms would prevent us from using Google Maps API in
I'm using Google Maps api v. 3 in my website. What I want to
I am using Google Maps API for reverse lookup of an address, specifically Country,
I'm using Google Maps V3 api. I am submitting an address search to return
I'm using Google Maps v3 and want it to load faster. My setup: At
I am using Google Maps V3 and I want to: Set the center of
I am using google maps geocoder to geocode a zipcode and I want it
I am using Google to take an address to get its lat and long.

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.