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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:44:37+00:00 2026-06-01T01:44:37+00:00

Note — Solved This is the function which is setting the center in my

  • 0

Note — Solved

This is the function which is setting the center in my map , with GPS locations i want more highest precise level and zoom level , what changes i have to make ?

package cc.co.ratan.www;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class Collegemap extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.collegemap);
    MapView view =(MapView) findViewById(R.id.themap);

    view.setBuiltInZoomControls(true); 

    final MapController control = view.getController();

    LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    LocationListener listner = new LocationListener() {

        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String arg0) {
            // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String arg0) {
            // TODO Auto-generated method stub

        }

        public void onLocationChanged(Location arg0) {
            // TODO Auto-generated method stub
            control.setCenter(new GeoPoint((int)arg0.getLatitude(), (int)arg0.getLongitude()));
        }
    };
            manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listner);



}

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

this is my code after i edited . (looked and made changes from your blog )

package cc.co.ratan.www;
import java.text.DecimalFormat;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class Collegemap extends MapActivity implements LocationListener{
private String provider;
GeoPoint myLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);

    //String provider;


    setContentView(R.layout.collegemap);

    MapView mview =(MapView) findViewById(R.id.themap);

    mview.setBuiltInZoomControls(true); 

    Criteria criteria = new Criteria();
    final MapController control = mview.getController();

             LocationManager manager = (LocationManager) 

            this.getSystemService(Context.LOCATION_SERVICE);
     Location location = manager.getLastKnownLocation(manager.NETWORK_PROVIDER);
     if (location != null)
            plotLocation(location);
        else
            manager.requestLocationUpdates(
                    manager.NETWORK_PROVIDER, 500L, 250.0f, (LocationListener) this);

    provider = manager.getBestProvider(criteria, false);

    LocationListener listner = new LocationListener() {

        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String arg0) {
            // TODO Auto-generated method stub
            Toast.makeText(Collegemap.this, "Enabled new provider " + provider,
                    Toast.LENGTH_SHORT).show();

        }

        public void onProviderDisabled(String arg0) {
            // TODO Auto-generated method stub
            Toast.makeText(Collegemap.this, "Disabled provider " + provider,
                    Toast.LENGTH_SHORT).show();

        }

        public void onLocationChanged(Location arg0) {
            // TODO Auto-generated method stub
            control.setCenter(new GeoPoint((int)arg0.getLatitude(), (int)arg0.getLongitude()));
        }
    };
            manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listner);

    ;

}

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

public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

}

double roundTwoDecimals(double d){
    DecimalFormat twoDForm = new DecimalFormat("#.######");
    return Double.valueOf(twoDForm.format(d));
    }
public void plotLocation(Location location) {
    GeoPoint point = new GeoPoint(
            (int) (roundTwoDecimals(location.getLatitude()) * 1E6),
            (int) (roundTwoDecimals(location.getLongitude()) * 1E6));
    myLocation = point;
    MapView mview =(MapView) findViewById(R.id.themap);
    mview.getController().animateTo(point);
    mview.getController().setCenter(point);
    zoomToMyLocation();}

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

}
private void zoomToMyLocation() {
    if (myLocation != null) {
        MapView mview =(MapView) findViewById(R.id.themap);
        mview.getController().setZoom(18);
        mview.getController().animateTo(myLocation);
    } 
}

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

}

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

}}
  • 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-01T01:44:38+00:00Added an answer on June 1, 2026 at 1:44 am

    @Ratan — I think some code is missing from your activity…
    Check below code plotmylocation will center map to gps location & zoomtomylocation will zoom map to that location you can add any zoom level there instead of 18 but I think 20 will be max value.

    public class MapDragActivity extends MapActivity implements LocationListener{
    String pinadd="";
    private MapView map=null;
    private LocationManager locationManager;
    GeoPoint myLocation;
    
    /** Called when the activity is first created. */
    
    @SuppressWarnings("static-access")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maplayout);
    
    
        map=(MapView)findViewById(R.id.map);
        map.setBuiltInZoomControls(true);
    
    
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    
        if (location != null)
            plotLocation(location);
        else
            locationManager.requestLocationUpdates(
                    locationManager.NETWORK_PROVIDER, 500L, 250.0f, this);
    
    }
    
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        if (location != null)
            plotLocation(location);
    }
    
    public void onProviderDisabled(String provider) {
    }
    
    public void onProviderEnabled(String provider) {
    }
    
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
    
    @SuppressWarnings("static-access")
    @Override
    public void onResume() {
            super.onResume();
            locationManager.requestLocationUpdates(
                    locationManager.NETWORK_PROVIDER, 1000L, 500.0f, this);
    }  
    
    @Override
    public void onPause() {
            super.onPause();
            locationManager.removeUpdates(this);
    } 
    
    @Override
    public void onDestroy(){
        locationManager.removeUpdates(this);
        super.onDestroy();
    }
    
    public void plotLocation(Location location) {
            GeoPoint point = new GeoPoint(
                    (int) (roundTwoDecimals(location.getLatitude()) * 1E6),
                    (int) (roundTwoDecimals(location.getLongitude()) * 1E6));
            myLocation = point;
            map.getController().animateTo(point);
            map.getController().setCenter(point);
            zoomToMyLocation();
    }
    
    private void zoomToMyLocation() {
        if (myLocation != null) {
            map.getController().setZoom(18);
            map.getController().animateTo(myLocation);
        } 
    }
    
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I have solved the majority of this problem but have run into a
NOTE: If you don't want to read this, check TLDR version at bottom of
Note : The code in this question is part of deSleeper if you want
Note: I'm more interested in understanding general Go concepts/patterns, rather than solving this contrived
Note: this was inspired by WebBrowser Event Properties? Why am I able to access
Note this question was originally posted in 2009, before C++11 was ratified and before
Note: This question has broadened in scope from previous revisions. I have tried to
Note: This issue appears to be limited to SQL Server 2005 SP2 I have
Note: I've read this and its not quite what I'm looking for: I have
NOTE Due to the successful outcome of this thread, the documentation at the provided

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.