¿Cómo haría que mi mapa de google se acercara a mi ubicación actual?

Hola me gustaría hacer mi mapa de zoom en mi ubicación actual. Esta ubicación actual se define actualmente enviando lat y largo al emulador. ¿Cómo iba a hacer esto?

Mi mapactivity.java actual

public class MapsActivity extends MapActivity { private MapView mapView; private MyLocationOverlay myLocOverlay; MapController mc; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapactivity); initMap(); initMyLocation(); } /** * Initialise the map and adds the zoomcontrols to the LinearLayout. */ private void initMap() { mapView = (MapView) findViewById(R.id.mapView); View zoomView = mapView.getZoomControls(); LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom); myzoom.addView(zoomView); mapView.displayZoomControls(true); mapView.getController().setZoom(17); } /** * Initialises the MyLocationOverlay and adds it to the overlays of the map */ private void initMyLocation() { myLocOverlay = new MyLocationOverlay(this, mapView); myLocOverlay.enableMyLocation(); mapView.getOverlays().add(myLocOverlay); } @Override protected boolean isRouteDisplayed() { return false; } 

Gracias.

Es necesario implementar onLocationChanged (). En mi código he añadido las superposiciones aquí también. Como mínimo debe establecer setCenter () con su ubicación actual

 public void onLocationChanged(Location location) { List<Overlay> overlays = mapView.getOverlays(); myLocOverlay = new MyLocationOverlay(this, mapView); overlays.add(myLocOverlay); myLocOverlay.enableMyLocation();* // definitely need what's below int lat = (int) (location.getLatitude() * 1E6); int lng = (int) (location.getLongitude() * 1E6); GeoPoint point = new GeoPoint(lat, lng); mc.setCenter(point); mapView.invalidate(); } 

Intente agregar esto al final de su código initMyLocation:

 controller = mapView.getController(); mMyLocOverlay.runOnFirstFix(new Runnable() { public void run() { controller.setZoom(17); controller.animateTo(mMyLocOverlay.getMyLocation()); } }); 

Puede quitar esta línea del método initMap:

 mapView.getController().setZoom(17); 

Avísame si funciona

Ale

Dado que ya dispone de los datos de ubicación, puede crear un objeto / estructura LatLng y utilizar esta línea directamente en el objeto Mapa:

 map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f)); 

Uso la API de Google Maps para Android v2

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.