Showing posts with label Google Map v2. Show all posts

Clustering on Google Map V2 Part-2

We have gone through Clustering on Google map V2 in Clustering on Google Map V2 Part-1 .To overcome drawback of it , I searched for few days and i found one more library which independent from google play service library.

Screenshots :


Features :

  • Clustering based on pixel proximity, not grid membership
  • Animated cluster transitions
  • Supports Android v2.2 (Froyo) and higher

Getting started : 

  • It's easy to add Clusterkraf to your app. Add the Clusterkraf library folder as an Android project to your Eclipse/ADT workspace, and reference it from your app as a library project.
  • Clusterkraf provides an InputPoint class which holds a LatLng position and an Object tag. You just need to construct an ArrayList<InputPoint> object based on your model objects.


    public class YourActivity extends FragmentActivity {
        YourMapPointModel[] yourMapPointModels = new YourMapPointModel[] { new YourMapPointModel(new LatLng(0d, 1d) /* etc */ ) };
        ArrayList inputPoints;
    
        private void buildInputPoints() {
            this.inputPoints = new ArrayList(yourMapPointModels.length);
            for (YourMapPointModel model : this.yourMapPointModels) {
                this.inputPoints.add(new InputPoint(model.latLng, model));
            }
        }
    }
    
  • When your GoogleMap is initialized and your ArrayList<InputPoint> is built, you can then initialize Clusterkraf.
    // YourActivity
    
        Clusterkraf clusterkraf;
    
        private void initClusterkraf() {
            if (this.map != null && this.inputPoints != null && this.inputPoints.size() > 0) {
                com.twotoasters.clusterkraf.Options options = new com.twotoasters.clusterkraf.Options();
                // customize the options before you construct a Clusterkraf instance
                this.clusterkraf = new Clusterkraf(this.map, this.options, this.inputPoints);
            }
        }
    


Advance Options :

  1. To set any type of interpolator in cluster animation :
    options.setTransitionInterpolator(interpolator); 
    /* Types : AccelerateDecelerateInterpolator, AccelerateInterpolator, AnticipateInterpolator,
    AnticipateOvershootInterpolator, BounceInterpolator, DecelerateInterpolator,
    LinearInterpolator, OvershootInterpolator */
    
  2. Clusterkraf calculates whether InputPoint objects should join a cluster based on their pixel proximity. If you want to offer your app on devices with different screen densities, you should identify a Device Independent Pixel measurement and convert it to pixels based on the device's screen density at runtime.
    options.setPixelDistanceToJoinCluster(dipDistanceToJoinCluster);
    
  3. To set zoom to bound animation duration :

    options.setZoomToBoundsAnimationDuration(zoomToBoundsAnimationDuration);
    
  4. To set showInfoWindow animation duration :

    options.setShowInfoWindowAnimationDuration(showInfoWindowAnimationDuration);
    
  5. To set behavior of marker click :

    options.setSinglePointClickBehavior(singlePointClickBehavior);
    /* select from two types SHOW_INFO_WINDOW, NO_OP. */
    
  6. To set behavior of cluster click :

    options.setClusterClickBehavior(this.options.clusterClickBehavior);
    /* select from three types ZOOM_TO_BOUNDS, SHOW_INFO_WINDOW, NO_OP. */
    
  7. To set behavior of cluster info window click :

    options.setClusterInfoWindowClickBehavior(this.options.clusterInfoWindowClickBehavior);
    /* select from three types ZOOM_TO_BOUNDS, HIDE_INFO_WINDOW, NO_OP. */
    
  8. To set padding from window sides after zooming :

    options.setZoomToBoundsPadding(pixels);
    /* When zooming to the bounds of a marker's backing ClusterPoint, zoom until
     * all of the points are at least this far from the edge of the GoogleMap's
     * bounds
     */
    
  9. To set marker click listner :

    options.setOnMarkerClickDownstreamListener(new OnMarkerClickDownstreamListener(new OnMarkerClickDownstreamListener() {
       
       @Override
       public boolean onMarkerClick(Marker marker, ClusterPoint clusterPoint) {
        // TODO Auto-generated method stub
        return false;
       }
      }));
    
  10. To get methods of starting and finishing clustering :

    options.setProcessingListener(this);
    /* generate two methods */
    @Override
     public void onClusteringStarted() {
      
     }
    
     @Override
     public void onClusteringFinished() {
     }

Download Source code : ClusterOnGoogleMapV2


Reference Link: Clusterkraf

Clustering on Google Map V2 Part-1

Introduction: 

I had done with clustering on Google Map V1. After it is deprecated, i was searching for clustering on Google Map V2. And i found one library Android Maps Extensions. It is working great but depends on your implementation how will you use it in your project.

Drawback : This library use google-play-services.jar and has its own implementation of GoogleMap. Hence if there will any change happen in Map v2 API, takes time to implement that changes in this library.

Screenshots:



Getting Started:

  1. Download zip from above link and import library project.
  2. Import this library to project.
    Note:
    No need to import google play service library project as this library contains it.
  3. Get Map key from API Console.

Map Implementation:

  • Activity extends FragmentActivity
  • FragmentManager fm = getSupportFragmentManager();
  • SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map); GoogleMap map = f.getExtendedMap();

Cluster Implementatioin:

map.setClustering(new ClusteringSettings().iconDataProvider(new DemoIconProvider(getResources())));


DemoIconProvider.java:


public class DemoIconProvider implements IconDataProvider {

 private static final int[] res = { R.drawable.m1, R.drawable.m2, R.drawable.m3, R.drawable.m4, R.drawable.m5 };

 private static final int[] forCounts = { 10, 100, 1000, 10000, Integer.MAX_VALUE };

 private Bitmap[] baseBitmaps;

 private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
 private Rect bounds = new Rect();

 private MarkerOptions markerOptions = new MarkerOptions().anchor(0.5f, 0.5f);

 public DemoIconProvider(Resources resources) {
  baseBitmaps = new Bitmap[res.length];
  for (int i = 0; i < res.length; i++) {
   baseBitmaps[i] = BitmapFactory.decodeResource(resources, res[i]);
  }
  paint.setColor(Color.WHITE);
  paint.setTextAlign(Align.CENTER);
  paint.setTextSize(resources.getDimension(R.dimen.text_size));
 }

 @Override
 public MarkerOptions getIconData(int markersCount) {
  Bitmap base;
  int i = 0;
  do {
   base = baseBitmaps[i];
  } while (markersCount >= forCounts[i++]);

  Bitmap bitmap = base.copy(Config.ARGB_8888, true);

  String text = String.valueOf(markersCount);
  paint.getTextBounds(text, 0, text.length(), bounds);
  float x = bitmap.getWidth() / 2.0f;
  float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top;

  Canvas canvas = new Canvas(bitmap);
  canvas.drawText(text, x, y, paint);

  BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(bitmap);
  return markerOptions.icon(icon);
 }
}

TO overcome from drawback, I found one library Clustering on Google Map V2 Part-2 .
It is easy to implement and more customizable.

Download Source code : ClusterMap2


Reference Link: Android Maps Extensions

Google Places API Tutorial

In this article i am going to talk about how to use Google Places API in Android. The Places API accepts search filter parameters. If you know that you're looking for a place with a particular word or string in its name, or if you're only interested in results that are restaurants, you can pass this information to the Places service for more accurate results.

Getting Started:

  1. Register your android project to get API Key in google console:
    https://code.google.com/apis/console/
  2. Get browser API
Note: Use browser API key rather than android API key.

1. To search for specific types of places (such as cafes), you can include the types parameter in your Places Search requests.

https://maps.googleapis.com/maps/api/place/search/json
  ?types=cafe
  &location=37.787930,-122.4074990
  &radius=5000
  &sensor=false
  &key=YOUR_API_KEY

2. Try specifying multiple place types by modifying the URL below to include other place types separated by a pipe ( | ) character in the URL. The Places Search API will return Places associated with any of the types that you specify. The example below demonstrates how to search for places that are considered a cafe or a bakery or both:
https://maps.googleapis.com/maps/api/place/search/json
  ?types=cafe|bakery
  &location=37.787930,-122.4074990
  &radius=5000
  &sensor=false
  &key=YOUR_API_KEY

3. To retrieve places based by distance:




    1. Remove the radius parameter from your Place Search request.
    2. Add a rankby=distance parameter/value pair.
    3. Include one or more of the keywordname, or types parameters.
For example, the URL below can be used to specify a search for cafes near downtown San Francisco, with results ordered by distance from the location:
https://maps.googleapis.com/maps/api/place/search/json
  ?types=cafe
  &rankby=distance
  &location=37.787930,-122.4074990
  &sensor=false
  &key=YOUR_API_KEY
4. To see more types that support Places API :
https://developers.google.com/places/documentation/supported_types

Place.java :

public class Place {
    private String id;
    private String icon;
    private String name;
    private String vicinity;
    private Double latitude;
    private Double longitude;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
    public Double getLatitude() {
        return latitude;
    }
    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }
    public Double getLongitude() {
        return longitude;
    }
    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getVicinity() {
        return vicinity;
    }
    public void setVicinity(String vicinity) {
        this.vicinity = vicinity;
    }

    static Place jsonToPontoReferencia(JSONObject pontoReferencia) {
        try {
            Place result = new Place();
            JSONObject geometry = (JSONObject) pontoReferencia.get("geometry");
            JSONObject location = (JSONObject) geometry.get("location");
            result.setLatitude((Double) location.get("lat"));
            result.setLongitude((Double) location.get("lng"));
            result.setIcon(pontoReferencia.getString("icon"));
            result.setName(pontoReferencia.getString("name"));
            result.setVicinity(pontoReferencia.getString("vicinity"));
            result.setId(pontoReferencia.getString("id"));
            return result;
        } catch (JSONException ex) {
            Logger.getLogger(Place.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String toString() {
        return "Place{" + "id=" + id + ", icon=" + icon + ", name=" + name + ", latitude=" + latitude + ", longitude=" + longitude + '}';
    }

}

PlacesService.java:

public class PlacesService {

 private String API_KEY;

 public PlacesService(String apikey) {
  this.API_KEY = apikey;
 }

 public void setApiKey(String apikey) {
  this.API_KEY = apikey;
 }

 public ArrayList findPlaces(double latitude, double longitude,
   String placeSpacification) {

  String urlString = makeUrl(latitude, longitude, placeSpacification);

  try {
   String json = getJSON(urlString);

   System.out.println(json);
   JSONObject object = new JSONObject(json);
   JSONArray array = object.getJSONArray("results");

   ArrayList arrayList = new ArrayList();
   for (int i = 0; i < array.length(); i++) {
    try {
     Place place = Place
       .jsonToPontoReferencia((JSONObject) array.get(i));
     Log.v("Places Services ", "" + place);
     arrayList.add(place);
    } catch (Exception e) {
    }
   }
   return arrayList;
  } catch (JSONException ex) {
   Logger.getLogger(PlacesService.class.getName()).log(Level.SEVERE,
     null, ex);
  }
  return null;
 }

 // https://maps.googleapis.com/maps/api/place/search/json?location=28.632808,77.218276&radius=500&types=atm&sensor=false&key=apikey
 private String makeUrl(double latitude, double longitude, String place) {
  StringBuilder urlString = new StringBuilder(
    "https://maps.googleapis.com/maps/api/place/search/json?");

  if (place.equals("")) {
   urlString.append("&location=");
   urlString.append(Double.toString(latitude));
   urlString.append(",");
   urlString.append(Double.toString(longitude));
   urlString.append("&radius=1000");
   // urlString.append("&types="+place);
   urlString.append("&sensor=false&key=" + API_KEY);
  } else {
   urlString.append("&location=");
   urlString.append(Double.toString(latitude));
   urlString.append(",");
   urlString.append(Double.toString(longitude));
   urlString.append("&radius=1000");
   urlString.append("&types=" + place);
   urlString.append("&sensor=false&key=" + API_KEY);
  }
  return urlString.toString();
 }

 protected String getJSON(String url) {
  return getUrlContents(url);
 }

 private String getUrlContents(String theUrl) {
  StringBuilder content = new StringBuilder();
  try {
   URL url = new URL(theUrl);
   URLConnection urlConnection = url.openConnection();
   BufferedReader bufferedReader = new BufferedReader(
     new InputStreamReader(urlConnection.getInputStream()), 8);
   String line;
   while ((line = bufferedReader.readLine()) != null) {
    content.append(line + "\n");
   }
   bufferedReader.close();
  }catch (Exception e) {
   e.printStackTrace();
  }
  return content.toString();
 }
}

MainActivity.java:

public class MainActivity extends Activity {

 private final String TAG = getClass().getSimpleName();
 private GoogleMap mMap;
 private String[] places;
 private LocationManager locationManager;
 private Location loc;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  initCompo();
  places = getResources().getStringArray(R.array.places);
  currentLocation();
  final ActionBar actionBar = getActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
  actionBar.setListNavigationCallbacks(ArrayAdapter.createFromResource(
    this, R.array.places, android.R.layout.simple_list_item_1),
    new ActionBar.OnNavigationListener() {
     @Override
     public boolean onNavigationItemSelected(int itemPosition,
       long itemId) {
      if (loc != null) {
       mMap.clear();
       new GetPlaces(MainActivity.this,
         places[itemPosition].toLowerCase().replace(
           "-", "_")).execute();
      }
      return true;
     }
    });
 }

 private class GetPlaces extends AsyncTask> {

  private ProgressDialog dialog;
  private Context context;
  private String places;

  public GetPlaces(Context context, String places) {
   this.context = context;
   this.places = places;
  }

  @Override
  protected void onPostExecute(ArrayList result) {
   super.onPostExecute(result);
   if (dialog.isShowing()) {
    dialog.dismiss();
   }
   for (int i = 0; i < result.size(); i++) {
    mMap.addMarker(new MarkerOptions()
      .title(result.get(i).getName())
      .position(
        new LatLng(result.get(i).getLatitude(), result
          .get(i).getLongitude()))
      .icon(BitmapDescriptorFactory
        .fromResource(R.drawable.pin))
      .snippet(result.get(i).getVicinity()));
   }
                        CameraPosition cameraPosition = new CameraPosition.Builder()
     .target(new LatLng(result.get(0).getLatitude(), result
       .get(0).getLongitude())) // Sets the center of the map to
           // Mountain View
     .zoom(14) // Sets the zoom
     .tilt(30) // Sets the tilt of the camera to 30 degrees
     .build(); // Creates a CameraPosition from the builder
   mMap.animateCamera(CameraUpdateFactory
     .newCameraPosition(cameraPosition));
  }

  @Override
  protected void onPreExecute() {
   super.onPreExecute();
   dialog = new ProgressDialog(context);
   dialog.setCancelable(false);
   dialog.setMessage("Loading..");
   dialog.isIndeterminate();
   dialog.show();
  }

  @Override
  protected ArrayList doInBackground(Void... arg0) {
   PlacesService service = new PlacesService(
     "Put your project browser API key here");
   ArrayList findPlaces = service.findPlaces(loc.getLatitude(), // 28.632808
     loc.getLongitude(), places); // 77.218276


   for (int i = 0; i < findPlaces.size(); i++) {

    Place placeDetail = findPlaces.get(i);
    Log.e(TAG, "places : " + placeDetail.getName());
   }
   return findPlaces;
  }
 }

 private void initCompo() {
  mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 private void currentLocation() {
  locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

  String provider = locationManager
    .getBestProvider(new Criteria(), false);

  Location location = locationManager.getLastKnownLocation(provider);

  if (location == null) {
   locationManager.requestLocationUpdates(provider, 0, 0, listener);
  } else {
   loc = location;
   new GetPlaces(MainActivity.this,
     places[0].toLowerCase().replace(
       "-", "_")).execute();
   Log.e(TAG, "location : " + location);
  }

 }

 private LocationListener listener = new LocationListener() {

  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
  }

  @Override
  public void onProviderEnabled(String provider) {
  }

  @Override
  public void onProviderDisabled(String provider) {
  }

  @Override
  public void onLocationChanged(Location location) {
   Log.e(TAG, "location update : " + location);
   loc = location;
   locationManager.removeUpdates(listener);
  }
 };
}

ScreenShots:



Source Code : Google Places API Demo

Note: Don't forget to add google play service library

Google Maps Android API V2

Introduction :

In Google map V2, You can use API calls to add markers, polygons, and overlays to a basic map, and to change the user's view of a particular map area.

The API allows you to add these graphics to a map:



  • Icons anchored to specific positions on the map (Markers).
  • Sets of line segments (Polylines) for drawing shapes.
  • Enclosed segments (Polygons), filled, unfilled or hollow.
  • Bitmap graphics anchored to specific positions on the map (Ground Overlays).
  • Sets of images which are displayed on top of the base map tiles (Tile Overlays). 


  • First you must add Google Play services as an Android library project as follows:
    1. Select File > Import > Android > Existing Android Code Into Workspace and click Next.
    2. Select Browse..., enter <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.

    Getting Started :

    Obtaining an API Key

    If your application is registered with the Google Maps Android API v2 service, then you can request an API key. It's possible to register more than one key per project.
    To get the key
    1. In the left navigation bar, click API Access.
    2. In the resulting page, click Create New Android Key....
    3. In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, then your application's package name. For example:
      BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;com.example.android.mapexample
    4. The Google APIs Console responds by displaying Key for Android apps (with certificates) followed by a forty-character API key, for example:
      AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
    5. Copy this key value. You will use it in the next step.
    Note: 
    1.  The Google Maps Android API v2 uses a new system of managing keys. Existing keys from a Google Maps Android v1 application, commonly known as MapView, will not work with the v2 API.
    2. To get SHA-1 fingerprint enter command in terminal: keytool -list -v -keystore debug.keystore

    Adding the API Key to your application

    1. In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing tag</application>:
      <meta-data
          android:name="com.google.android.maps.v2.API_KEY"
          android:value="your_api_key"/>
      
      substituting your API key for your_api_key. This element sets the key com.google.android.maps.v2.API_KEY to the value your_api_key and makes the API key visible to any MapFragment in your application.
    2. Add the following elements to your manifest. Replace com.example.mapdemo with the package name of your application.
              <permission
                android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
                android:protectionLevel="signature"/>
              <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
          
    3. Save AndroidManifest.xml and re-build your application. 
    Specifying permissions
    Besides permissions required by other parts of your application, you must add the following permissions in order to use the Google Maps Android API:
    • android.permission.INTERNET Used by the API to download map tiles from Google Maps servers.
    • com.google.android.providers.gsf.permission.READ_GSERVICES Allows the API to access Google web-based services.

      <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
      
    • android.permission.WRITE_EXTERNAL_STORAGE Allows the API to cache map tile data in the device's external storage area.
    Requiring OpenGL ES version 2
    Because version 2 of the Google Maps Android API requires OpenGL ES version 2, you must add a <uses-feature> element as a child of the<manifest> element in AndroidManifest.xml:
    <uses-feature
      android:glEsVersion="0x00020000"
      android:required="true"/>
    

    Sample Code:

    Examples of how to add more robust code appear throughout this guide and in the sample code.
    1. In main.xml, add the following fragment.
      <?xml version="1.0" encoding="utf-8"?>
      <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment"/>
      
    2. In MainActivity.java, add the following code.
      package com.example.mapdemo;
      import android.app.Activity;
      import android.os.Bundle;
      public class MainActivity extends Activity {
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
          }
      }
      
    3. Build and run your application. You should see a map. If you don't see a map, confirm that you've completed all of the steps appearing earlier in this document.

    Adding Map Code

    private GoogleMap mMap;
    ...
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    Change the Map Type

    To set the type of a map, call the GoogleMap object's setMapType() method, passing one of the type constants defined in GoogleMap. For example, to display a satellite map:
    GoogleMap map;
    ...
    // Sets the map type to be "hybrid"
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    

    Add a marker

    The below example demonstrates how to add a marker to a map. The marker is created at coordinates 0,0, and displays the string "Hello world" in an infowindow when clicked.
    private GoogleMap mMap;
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    mMap.addMarker(new MarkerOptions()
            .position(new LatLng(0, 0))
            .title("Hello world"));
    
    The below snippet creates a marker with a custom icon.
      private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
      private Marker melbourne = mMap.addMarker(new MarkerOptions()
                                .position(MELBOURNE)
                                .title("Melbourne")
                                .snippet("Population: 4,137,400")
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
    

    Info windows

    An info window allows you to display information to the user when they tap on a marker on a map. By default, an info window is displayed when a user taps on a marker if the marker has a title set. Only one info window is displayed at a time. If a user clicks on another marker, the current window will be hidden and the new info window will be displayed. You can show an info window programmatically by calling showInfoWindow() on the target marker. An info window can be hidden by calling hideInfoWindow().

    Info window click events

    You can use an OnInfoWindowClickListener to listen to click events on an info window. You need to implement OnInfoWindowClickListener to activity.
    @Override
        public void onInfoWindowClick(Marker marker) {
               }

    Marker click events

    You can use an OnMarkerClickListener to listen for click events on the marker. To set this listener on the map, callGoogleMap.setOnMarkerClickListener(OnMarkerClickListener). When a user clicks on a marker, onMarkerClick(Marker) will be called and the marker will be passed through as an argument.

    Interacting with the map :

    The Maps API comes with some built-in UI controls that are similar to those found in the Google Maps application on your Android phone. You can toggle the visibility of these controls using the UiSettings class which can be obtained from a GoogleMap with the GoogleMap.getUiSettings method.

    Zoom controls

    The Maps API provides built-in zoom controls that appear in the bottom right hand corner of the map. These are enabled by default, but can be disabled by calling UiSettings.setZoomControlsEnabled(boolean).

    Compass

    The Maps API provides a compass graphic which appears in the top left corner of the map under certain circumstances.You can disable the compass appearing altogether by calling  UiSettings.setCompassEnabled(boolean).

    My Location button

    The My Location button appears in the top right corner of the screen only when the My Location layer is enabled. When a user clicks the button, the camera animates to focus on the user's current location if the user's location is currently known. You can disable the button from appearing altogether by callingUiSettings.setMyLocationButtonEnabled(boolean).

    Moving Camera

     The following code snippets illustrate some of the common ways to move the camera using the Maps API.
    private static final LatLng SYDNEY = new LatLng(-33.88,151.21);
    private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);
    private GoogleMap map;
    ... // Obtain the map from a MapFragment or MapView.
    // Move the camera instantly to Sydney with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15);
    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomIn());
    // Zoom out to zoom level 10, animating with a duration of 2 seconds.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), null, 2000);
    // Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
    CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(MOUNTAIN_VIEW)      // Sets the center of the map to Mountain View
        .zoom(17)                   // Sets the zoom
        .bearing(90)                // Sets the orientation of the camera to east
        .tilt(30)                   // Sets the tilt of the camera to 30 degrees
        .build();                   // Creates a CameraPosition from the builder
    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));