I implement map in my device successfully.
but now I want to add functionality
When I click on Button then I want to get Current Location in map.
How can I do that?

I implement map in my device successfully.
but now I want to add functionality
When I click on Button then I want to get Current Location in map.
How can I do that?

You can add listener on button click.
Button btnMyLocation = (Button) findViewById(R.id.btnMyLocation);
CameraUpdate cameraUpdate = null;
btnMyLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Location loc = map.getMyLocation();
if (loc != null) {
LatLng latLng = new LatLng(loc.getLatitude(), loc
.getLongitude());
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 17);
map.animateCamera(cameraUpdate);
}
}
});
for GPS :
You require following permission in Manifest file
android.permission.ACCESS_FINE_LOCATION
and here is code :
final LocationManager manager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE );
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
Toast.makeText(context, "GPS is disable!", Toast.LENGTH_LONG).show();
else
Toast.makeText(context, "GPS is Enable!", Toast.LENGTH_LONG).show();
Just start a location Update listener on the click of that button. and when new location arrives move the camera in mapObject (got in OnMapReady() method) to that location with animations.
i have a similar trouble, in my case work with this:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(loc.getLatitude(), loc.getLongitude()), 4));
Regards