title: Android Google Maps API V2 not zooming to Location
body: <p>Im not sure whats wrong but Im trying to get my google maps fragment to zoom in to a particular location on start. For some reason, it is not working and still zooms in to africa by default. Here is my code.</p>
  
  <pre><code>public class OutbreakMap extends Activity implements LocationListener {
      double lat=50;
      double longi=50;
      private LocationManager locationManager;
      private String provider;
      private MapFragment mMapFragment;
      private GoogleMap googleMap;
  
  
      /** Called when the activity is first created. */
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.location);
  
          // Get the location manager
          locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
          LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
          boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
  
           // Check if enabled and if not send user to the GSP settings
           // Better solution would be to display a dialog and suggesting to
          // go to the settings
          if (!enabled) {
              AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
  
              // set title
              alertDialogBuilder.setTitle("Turn On Your GPS");
  
              // set dialog message
              alertDialogBuilder
                      .setMessage("Please turn on your GPS to track sickness in your area!")
                      .setCancelable(false)
                      .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog,int id) {
                              // if this button is clicked, close
                              // current activity
                              OutbreakMap.this.finish();
                              Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                              startActivity(intent);
                          }
                      })
                      .setNegativeButton("No",new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog,int id) {
                              // if this button is clicked, just close
                              // the dialog box and do nothing
                              dialog.cancel();
                          }
                      });
  
              // create alert dialog
              AlertDialog alertDialog = alertDialogBuilder.create();
  
              // show it
              alertDialog.show();
  
          }
          // Define the criteria how to select the locatioin provider -&gt; use
          // default
          Criteria criteria = new Criteria();
          provider = locationManager.getBestProvider(criteria, false);
          Location location = locationManager.getLastKnownLocation(provider);
  
          // Initialize the location fields
          if (location != null) {
              System.out.println("Provider " + provider + " has been selected.");
              onLocationChanged(location);
          } else {
              Toast.makeText(getApplicationContext(),"Location not found",Toast.LENGTH_SHORT);
          }
  
          mMapFragment = MapFragment.newInstance();
          FragmentTransaction fragmentTransaction =
                  getFragmentManager().beginTransaction();
          fragmentTransaction.add(R.id.map, mMapFragment);
          fragmentTransaction.commit();
          googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                  .getMap();
          setUpMapIfNeeded();
          googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
          if(location != null)  {
              lat=location.getLatitude();
              longi=location.getLongitude();
          }
  
          CameraPosition cameraPosition = new CameraPosition.Builder()
                      .target(new LatLng(lat,longi))      // Sets the center of the map to Mountain View
                      .zoom(17)                   // Sets the zoom
                    // Sets the tilt of the camera to 30 degrees
                      .build();                   // Creates a CameraPosition from the builder
          googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
  
          UiSettings uiSettings=googleMap.getUiSettings();
          uiSettings.setAllGesturesEnabled(false);
          // Initialize the location fields
          if (location != null) {
              System.out.println("Provider " + provider + " has been selected.");
              onLocationChanged(location);
          } else {
          Toast.makeText(getApplicationContext(),"Couldn't Find Location",Toast.LENGTH_SHORT);
          }
  
  
  
          ParseGeoPoint userLoc= new ParseGeoPoint(lat,longi);
          ParseQuery query= new ParseQuery("Outbreak");
          query.whereWithinMiles("location",userLoc,1);
          query.findInBackground(new FindCallback() {
              public void done(List&lt;ParseObject&gt; objects, ParseException e) {
                  if (e == null) {
                  GetOutbreaks.getOutBreaksNearMe(googleMap,lat,longi,objects);
                  Toast.makeText(getApplicationContext(),"Recieved Outbreak Data",Toast.LENGTH_SHORT);
                  } else {
                      e.printStackTrace();
                      Toast.makeText(getApplicationContext(),"Could Not Download    Data",Toast.LENGTH_SHORT);
                  }
              }
  
          });
  
  
  //        moveToPrescription();
  //        moveToPrescription();
      }
  
      /* Request updates at startup */
      @Override
      protected void onResume() {
          super.onResume();
          locationManager.requestLocationUpdates(provider, 400, 1, this);
      }
  
      /* Remove the locationlistener updates when Activity is paused */
      @Override
      protected void onPause() {
          super.onPause();
          locationManager.removeUpdates(this);
      }
  
      @Override
      public void onLocationChanged(Location location) {
          int lat = (int) (location.getLatitude());
          int lng = (int) (location.getLongitude());
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onProviderEnabled(String provider) {
          Toast.makeText(this, "Enabled new provider " + provider,
                  Toast.LENGTH_SHORT).show();
  
      }
  
      @Override
      public void onProviderDisabled(String provider) {
          Toast.makeText(this, "Disabled provider " + provider,
                  Toast.LENGTH_SHORT).show();
      }
  
      public void moveToPrescription(){
          Intent intent = new Intent(this,Prescription.class);
          startActivity(intent);
  
      }
  
      private void setUpMapIfNeeded() {
          // Do a null check to confirm that we have not already instantiated the map.
          if (googleMap == null) {
              googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                      .getMap();
              // Check if we were successful in obtaining the map.
              if (googleMap != null) {
                  // The Map is verified. It is now safe to manipulate the map.
  
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Also, here is my xml layout for the map fragment activity</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" &gt;
  
          &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/map"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:name="com.google.android.gms.maps.MapFragment"/&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And my Android manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.parse.starter"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/&gt;
      &lt;permission
              android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
              android:protectionLevel="signature"/&gt;
      &lt;uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
      &lt;!-- The following two permissions are not required to use
           Google Maps Android API v2, but are recommended. --&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
  
      &lt;application
          android:name="ParseApplication"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".ParseStarterProjectActivity"
  
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".Register"/&gt;
          &lt;activity android:name=".Login"/&gt;
          &lt;activity android:name=".Home"/&gt;
          &lt;activity android:name=".OutbreakMap"/&gt;
          &lt;activity android:name=".Prescription"/&gt;
          &lt;activity android:name=".MyPrescriptions"/&gt;
          &lt;receiver android:name=".AlarmManagerBroadcastReceiver"&gt;&lt;/receiver&gt;
  
          &lt;uses-library android:name="com.google.android.maps"/&gt;
          &lt;meta-data
                  android:name="com.google.android.maps.v2.API_KEY"
                  android:value="My Maps API Key is Here"/&gt;
      &lt;/application&gt;
      &lt;uses-feature android:glEsVersion="0x00020000" android:required="true" /&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The LogCat is not showing any errors. Thanks for the help!</p>