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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:40:49+00:00 2026-05-24T04:40:49+00:00

i want to open or focus to my current location in google map in

  • 0

i want to open or focus to my current location in google map in android. I want my app to get coordinates and then give the name of my location from these coordinates and also in the end focus the current location map…
Kindly someone suggest me what and how to do and if possible give me some code sample. i m new to android 🙂
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-05-24T04:40:50+00:00Added an answer on May 24, 2026 at 4:40 am

    here is the example of simple map display with current location

    MyMap.java for display map

    class MyMap extends MapActivity{
    /** Called when the activity is first created. */
    GeoPoint defaultPoint;
    static GeoPoint point;
    static MapController mc;
    static MapView mapView;
    static double curLat =0;
    static double curLng =0;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mapView = (MapView)findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
    
        String coordinates[] = {"22.286595", "70.795685"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
    
        mc = mapView.getController();
    
        defaultPoint = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));
    
        mc.animateTo(defaultPoint);
        mc.setZoom(13); 
    
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);   
    
        mapView.invalidate();
    
        Intent startService = new Intent(getApplicationContext(),ServiceLocation.class);
        startService(startService);
    }
    
    public static void updateMap() {
        if(ServiceLocation.curLocation!=null){
            curLat = ServiceLocation.curLocation.getLatitude();
            curLng = ServiceLocation.curLocation.getLongitude();        
            if(mapView!=null){
                point = new GeoPoint((int)(curLat*1e6),(int)(curLng*1e6));
                mc.animateTo(point);
                mapView.invalidate();
            }
        }
    }
    @Override
    protected boolean isRouteDisplayed(){
        return false;
    }
    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);                   
    
            if(!shadow){
                //---translate the GeoPoint to screen pixels---
                Point screenPts = new Point();
                if(curLat==0 && curLng==0)
                    mapView.getProjection().toPixels(defaultPoint, screenPts);
                else{
                    mapView.getProjection().toPixels(point, screenPts);
                }
                //---add the marker---
                Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.cur_loc);            
                canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
            }
            return true;
        }
    }
    }
    

    here is my background service code for fetching lat/lng using gps

    class ServiceLocation extends Service{
    private LocationManager locMan;
    private Boolean locationChanged;
    private Handler handler = new Handler();
    
    public static Location centerLoc;
    public static Location curLocation;
    public static boolean isService = true;
    
    
    LocationListener gpsListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            if (curLocation == null) {
                curLocation = location;
                locationChanged = true;
            }else if (curLocation.getLatitude() == location.getLatitude() && curLocation.getLongitude() == location.getLongitude()){
                locationChanged = false;
                return;
            }else
                locationChanged = true;
    
            curLocation = location;
    
    
            if (locationChanged)
                locMan.removeUpdates(gpsListener);
    
    
        MyMap.updateMap();
        }
        public void onProviderDisabled(String provider) {
        }
    
        public void onProviderEnabled(String provider) {
            // Log.w("GPS", "Location changed", null);
        }
    
        public void onStatusChanged(String provider, int status,Bundle extras) {
            if (status == 0)// UnAvailable
            {
            } else if (status == 1)// Trying to Connect
            {
            } else if (status == 2) {// Available
            }
        }
    
    };
    
    @Override
    public void onCreate() {
        super.onCreate();
        if (locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
           locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,100, 1, gpsListener);
        } else {
           this.startActivity(new Intent("android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS"));
        }
        centerLoc = new Location("");
        curLocation = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);;*/
        centerLoc = new Location("");
        curLocation = getBestLocation();
    
        if (curLocation == null) 
            Toast.makeText(getBaseContext(),"Unable to get your location", Toast.LENGTH_SHORT).show();
    
        isService =  true;
    }
    final String TAG="LocationService";
       @Override
       public int onStartCommand(Intent intent, int flags, int startId) {
     return super.onStartCommand(intent, flags, startId);
       }
    
    
    
    @Override
       public void onLowMemory() {
           super.onLowMemory();
       }
    
       @Override
       public void onStart(Intent i, int startId){
          handler.postDelayed(GpsFinder,5000);// will start after 5 seconds
       }
    
       @Override
       public void onDestroy() {
           handler.removeCallbacks(GpsFinder);
           handler = null;
           Toast.makeText(this, "Stop services", Toast.LENGTH_SHORT).show();
           isService = false;
       }
    
       public IBinder onBind(Intent arg0) {
             return null;
      }
    
      public Runnable GpsFinder = new Runnable(){
        public void run(){
            Location tempLoc = getBestLocation();
            if(tempLoc!=null)
                curLocation = tempLoc;
            handler.postDelayed(GpsFinder,5000);// register again to start after 5 seconds...        
        }
      };
    
        private Location getBestLocation() {        
            Location gpslocation = null;
            Location networkLocation = null;
    
            if(locMan==null)
                  locMan = (LocationManager) getApplicationContext() .getSystemService(Context.LOCATION_SERVICE);
            try {
                if(locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)){
                    locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,100, 1, gpsListener);
                    gpslocation = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                }
                if(locMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
                    locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,100, 1, gpsListener);
                    networkLocation = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
                }
            } catch (IllegalArgumentException e) {
                //Log.e(ErrorCode.ILLEGALARGUMENTERROR, e.toString());
                Log.e("error", e.toString());
    
            }
            if(gpslocation==null && networkLocation==null)
                return null;
    
            if(gpslocation!=null && networkLocation!=null){
                if(gpslocation.getTime() < networkLocation.getTime())
                    return networkLocation;
                else
                    return gpslocation;
            }
            if (gpslocation == null) {
                return networkLocation;
            }
            if (networkLocation == null) {
                return gpslocation;
            }
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to open an inbuilt google map intent to show route between two
I want to be able to open Android's stock Wifi Settings screen from my
I want open a path to vim from Screen's copy-mode by Ctrl-A f similarly
Want to open firefox from terminal at linux with firebug enabled // Terminal $
I want to open a website, change its javascript, then show the website +
I want to open a MFC modeless dialog from a MFC dll injected into
I want to open a popup when the focus is on a text box
When I have 2 apps open and one has the focus but I want
I want to redirect a new tab and to get focus of the new
I want to get focus or select an window which pop-up's on click to

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.