0

google map v2 in android how to get current position and zoom in automatically and main countries selection point notification

setContentView(R.layout.activity_main);

     try {

            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

}
     @SuppressLint("NewApi")
    private void initilizeMap() {
            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager().findFragmentById(

                        R.id.map)).getMap();

googleMap.animateCamera(CameraUpdateFactory.zoomTo(5.0f));

                LocationManager mlocManager = 

(LocationManager)getSystemService(Context.LOCATION_SERVICE);

                googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(0, 0))
                .title("Your Location is"));



                        if (googleMap == null) {
                    Toast.makeText(getApplicationContext(),
                            "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        } 
        protected void onResume() {
            super.onResume();
            initilizeMap();
        } 
user3066085
  • 128
  • 1
  • 8
  • 1
    You can't expect that other users will solve your complete problem. There are a lot of similar questions like: "How to get current location" (http://stackoverflow.com/questions/17591147/how-to-get-current-location-in-android) or "How to get current location programmatically" (http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android). – owe Jan 30 '14 at 14:03
  • no i have solved my problem there is left only bit of problem that is current location how to get only – user3066085 Jan 30 '14 at 14:04
  • You just need the current position? Nothing more? – owe Jan 30 '14 at 14:06
  • yes i want only my current position – user3066085 Jan 30 '14 at 14:08
  • Read the official doc: https://developer.android.com/training/location/index.html – fasteque Jan 30 '14 at 14:29

1 Answers1

2

After analysing your question you could try this:

private LatLng getCurrentPosition(){
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();             // set criteria for location provider:
    criteria.setAccuracy(Criteria.ACCURACY_FINE);   // fine accuracy
    criteria.setCostAllowed(false);                 // no monetary cost

    String bestProvider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(bestProvider);
    LatLng myPosition= new LatLng(location.getLatitude(), location.getLongitude());
    Toast.makeText(this, "current position: "+ location.getLatitude() + "," + location.getLongitude(), Toast.LENGTH_SHORT).show();
    return myPosition; 
}
owe
  • 4,890
  • 7
  • 36
  • 47