com.google.android.gms.maps.CameraUpdate Java Examples

The following examples show how to use com.google.android.gms.maps.CameraUpdate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationPickerActivity.java    From LocationPicker with MIT License 6 votes vote down vote up
private void addMarker() {

        LatLng coordinate = new LatLng(mLatitude, mLongitude);
        if (mMap != null) {
            MarkerOptions markerOptions;
            try {
                mMap.clear();
                imgSearch.setText("" + userAddress);

                markerOptions = new MarkerOptions().position(coordinate).title(userAddress).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_place_red_800_24dp));
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(coordinate, 14);
                mMap.animateCamera(cameraUpdate);
                mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

                Marker marker = mMap.addMarker(markerOptions);
                marker.showInfoWindow();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    }
 
Example #2
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade las marcas de todas las Ubicaciones
 * @param ubicaciones
 */
private void marcarUbicaciones(ArrayList<Ubicacion> ubicaciones) {

    if (ubicaciones.size() > 0) {
        for (Ubicacion ubicacion : ubicaciones) {

            marcarUbicacion(ubicacion);
        }
    }

    // Posiciona la vista del usuario en Zaragoza
    CameraUpdate camara =
            CameraUpdateFactory.newLatLng(Constantes.ZARAGOZA);

    // Coloca la vista del mapa sobre la posición de la ciudad
    // y activa el zoom para verlo de cerca
    mapa.moveCamera(camara);
    mapa.animateCamera(CameraUpdateFactory.zoomTo(9.0f), 2000, null);
}
 
Example #3
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade las marcas de todas las gasolineras
 * @param gasolineras
 */
private void marcarGasolineras(ArrayList<Gasolinera> gasolineras) {
	
	if (gasolineras.size() > 0) {
		for (Gasolinera gasolinera : gasolineras) {
			
			marcarGasolinera(gasolinera);
		}
	}
	
	// Posiciona la vista del usuario en Zaragoza
   	CameraUpdate camara =
   			CameraUpdateFactory.newLatLng(Constantes.ZARAGOZA);
       	 
   	// Coloca la vista del mapa sobre la posición de la ciudad 
   	// y activa el zoom para verlo de cerca
   	mapa.moveCamera(camara);
   	mapa.animateCamera(CameraUpdateFactory.zoomTo(9.0f), 2000, null);
}
 
Example #4
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Marca el restaurante elegido en el mapa
 */
private void ubicarRestaurante() {

    // Obtiene una vista de cámara
    CameraUpdate camara =
            CameraUpdateFactory.newLatLng(new LatLng(latitud, longitud));

    // Coloca la vista del mapa sobre la posición del restaurante
    // y activa el zoom para verlo de cerca
    mapa.moveCamera(camara);
    mapa.animateCamera(CameraUpdateFactory.zoomTo(17.0f));

    // Añade una marca en la posición del restaurante con el nombre de éste
    mapa.addMarker(new MarkerOptions()
            .position(new LatLng(latitud, longitud))
            .title(nombre));

    mapa.setMyLocationEnabled(true);
}
 
Example #5
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade la marca de una Ubicación
 * @param ubicacion
 */
private void marcarUbicacion(Ubicacion ubicacion) {

    // Prepara y añade una nueva marca al mapa
    mapa.addMarker(new MarkerOptions()
            .position(ubicacion.getPosicion())
            .title(ubicacion.getNombre()));

    // Posiciona la vista del usuario en el punto que se acaba de agregar
    CameraUpdate camara =
            CameraUpdateFactory.newLatLng(ubicacion.getPosicion());

    // Coloca la vista del mapa sobre la posición de la gasolinera
    // y activa el zoom para verlo de cerca
    mapa.moveCamera(camara);
    mapa.animateCamera(CameraUpdateFactory.zoomTo(12.0f), 2000, null);
}
 
Example #6
Source File: BusinessDetailsActivity.java    From YelpQL with MIT License 6 votes vote down vote up
private void showPointerOnMap(final double latitude, final double longitude) {
    mvRestaurantLocation.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            LatLng latLng = new LatLng(latitude, longitude);
            googleMap.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_flag))
                    .anchor(0.0f, 1.0f)
                    .position(latLng));
            googleMap.getUiSettings().setMyLocationButtonEnabled(false);
            googleMap.getUiSettings().setZoomControlsEnabled(true);

            // Updates the location and zoom of the MapView
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
            googleMap.moveCamera(cameraUpdate);
        }
    });
}
 
Example #7
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade la marca de una gasolinera
    * @param gasolinera
 */
private void marcarGasolinera(Gasolinera gasolinera) {
	
	// Prepara y añade una nueva marca al mapa
	mapa.addMarker(new MarkerOptions()
		.position(gasolinera.getPosicion())
		.title(gasolinera.getNombre()));
	
	// Posiciona la vista del usuario en el punto que se acaba de agregar
   	CameraUpdate camara =
   			CameraUpdateFactory.newLatLng(gasolinera.getPosicion());
       	 
   	// Coloca la vista del mapa sobre la posición de la gasolinera 
   	// y activa el zoom para verlo de cerca
   	mapa.moveCamera(camara);
   	mapa.animateCamera(CameraUpdateFactory.zoomTo(12.0f), 2000, null);
}
 
Example #8
Source File: Android_Mapas.java    From android with GNU General Public License v2.0 6 votes vote down vote up
private void localizarGasolinera() {
	
	if (spGasolineras.getSelectedItemPosition() == Spinner.INVALID_POSITION) {
		return;
	}
	
	Gasolinera gasolinera = listaGasolineras.get(spGasolineras.getSelectedItemPosition());
	
	// Prepara y añade una nueva marca al mapa
	mapa.addMarker(new MarkerOptions()
		.position(gasolinera.getPosicion())
		.title(gasolinera.getNombre()));
	
	// Posiciona la vista del usuario en el punto que se acaba de agregar
   	CameraUpdate camara =
   			CameraUpdateFactory.newLatLng(gasolinera.getPosicion());
       	 
   	// Coloca la vista del mapa sobre la posición del restaurante
   	// y activa el zoom para verlo de cerca
   	mapa.moveCamera(camara);
   	mapa.animateCamera(CameraUpdateFactory.zoomTo(12.0f)); 
}
 
Example #9
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade las marcas de todas las Ubicaciones
 * @param ubicaciones
 */
private void marcarUbicaciones(ArrayList<Ubicacion> ubicaciones) {

    if (ubicaciones.size() > 0) {
        for (Ubicacion ubicacion : ubicaciones) {

            marcarUbicacion(ubicacion);
        }
    }

    // Posiciona la vista del usuario en Zaragoza
    CameraUpdate camara =
            CameraUpdateFactory.newLatLng(Constantes.ZARAGOZA);

    // Coloca la vista del mapa sobre la posición de la ciudad
    // y activa el zoom para verlo de cerca
    mapa.moveCamera(camara);
    mapa.animateCamera(CameraUpdateFactory.zoomTo(9.0f), 2000, null);
}
 
Example #10
Source File: MapViewPager.java    From MapViewPager with Apache License 2.0 6 votes vote down vote up
private void moveToSingle(Adapter adapter, int index, boolean animate) {
    CameraPosition cp = adapter.getCameraPosition(index);
    CameraUpdate cu;
    if (cp != null && cp.target != null
            && cp.target.latitude != 0.0
            && cp.target.longitude != 0.0) {
        cu = CameraUpdateFactory.newCameraPosition(cp);
        if (hidden) showMarkers();
        if (markers.get(index) != null) markers.get(index).showInfoWindow();
    }
    else {
        cu = defaultPosition;
        hideInfoWindowSingle();
    }
    if (animate) map.animateCamera(cu);
    else map.moveCamera(cu);
}
 
Example #11
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade la marca de una gasolinera
    * @param gasolinera
 */
private void marcarGasolinera(Gasolinera gasolinera) {
	
	// Prepara y añade una nueva marca al mapa
	mapa.addMarker(new MarkerOptions()
		.position(gasolinera.getPosicion())
		.title(gasolinera.getNombre()));
	
	// Posiciona la vista del usuario en el punto que se acaba de agregar
   	CameraUpdate camara =
   			CameraUpdateFactory.newLatLng(gasolinera.getPosicion());
       	 
   	// Coloca la vista del mapa sobre la posición de la gasolinera 
   	// y activa el zoom para verlo de cerca
   	mapa.moveCamera(camara);
   	mapa.animateCamera(CameraUpdateFactory.zoomTo(12.0f), 2000, null);
}
 
Example #12
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade las marcas de todas las gasolineras
 * @param gasolineras
 */
private void marcarGasolineras(ArrayList<Gasolinera> gasolineras) {
	
	if (gasolineras.size() > 0) {
		for (Gasolinera gasolinera : gasolineras) {
			
			marcarGasolinera(gasolinera);
		}
	}
	
	// Posiciona la vista del usuario en Zaragoza
   	CameraUpdate camara =
   			CameraUpdateFactory.newLatLng(Constantes.ZARAGOZA);
       	 
   	// Coloca la vista del mapa sobre la posición de la ciudad 
   	// y activa el zoom para verlo de cerca
   	mapa.moveCamera(camara);
   	mapa.animateCamera(CameraUpdateFactory.zoomTo(9.0f), 2000, null);
}
 
Example #13
Source File: MapsActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onConnected(@Nullable Bundle bundle) {


    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);


    LatLng latLng = new LatLng(mLocation.getLatitude(), mLocation.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 12);
    mMap.animateCamera(cameraUpdate);


    startLocationUpdates();

}
 
Example #14
Source File: LocationGeofenceEditorActivity.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
private float getCircleZoomValue(double latitude, double longitude, double radius,
                               float minZoom, float maxZoom) {
    LatLng position = new LatLng(latitude, longitude);
    float currZoom = (minZoom + maxZoom) / 2;
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(position, currZoom);
    mMap.moveCamera(camera);
    float[] results = new float[1];
    LatLng topLeft = mMap.getProjection().getVisibleRegion().farLeft;
    LatLng topRight = mMap.getProjection().getVisibleRegion().farRight;
    Location.distanceBetween(topLeft.latitude, topLeft.longitude, topRight.latitude,
                                topRight.longitude, results);
    // Difference between visible width in meters and 2.5 * radius.
    double delta = results[0] - 2.5 * radius;
    double accuracy = 10; // 10 meters.
    if (delta < -accuracy)
        return getCircleZoomValue(latitude, longitude, radius, minZoom, currZoom);
    else
    if (delta > accuracy)
        return getCircleZoomValue(latitude, longitude, radius, currZoom, maxZoom);
    else
        return currZoom;
}
 
Example #15
Source File: MyTracksMapFragment.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the current location.
 * 
 * @param forceZoom true to force zoom to the current location regardless of
 *          the keepCurrentLocationVisible policy
 */
private void updateCurrentLocation(final boolean forceZoom) {
  getActivity().runOnUiThread(new Runnable() {
    public void run() {
      if (!isResumed() || googleMap == null || onLocationChangedListener == null
          || currentLocation == null) {
        return;
      }
      onLocationChangedListener.onLocationChanged(currentLocation);
      if (forceZoom || (keepCurrentLocationVisible && !isLocationVisible(currentLocation))) {
        LatLng latLng = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
        CameraUpdate cameraUpdate = forceZoom ? CameraUpdateFactory.newLatLngZoom(
            latLng, DEFAULT_ZOOM_LEVEL)
            : CameraUpdateFactory.newLatLng(latLng);
        googleMap.animateCamera(cameraUpdate);
      }
    };
  });
}
 
Example #16
Source File: GeofieldFragment.java    From mobile-android-survey-app with MIT License 6 votes vote down vote up
private void setLocation(double latitude, double longitude, boolean marker) {
    Log.i(this, "setLocation %f,%f", latitude, longitude);
    this.latitude = latitude;
    this.longitude = longitude;
    if (latitude != 0.0 && longitude != 0.0 && marker) {
        if (map != null) {
            map.clear();
            LatLng latLng = new LatLng(latitude, longitude);
            map.addMarker(new MarkerOptions()
                    .position(latLng)
                    .draggable(true)
                    .title(getString(R.string.current_location))
                    .snippet(String.format("%f,%f", latitude, longitude)));
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
            map.animateCamera(cameraUpdate);
        }
    }
}
 
Example #17
Source File: MyTracksMapFragment.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Shows a marker by moving the camera over the marker.
 * 
 * @param id the marker id
 */
private void showMarker(final long id) {
  getActivity().runOnUiThread(new Runnable() {
      @Override
    public void run() {
      if (!isResumed() || googleMap == null) {
        return;
      }
      MyTracksProviderUtils MyTracksProviderUtils = Factory.get(getActivity());
      Waypoint waypoint = MyTracksProviderUtils.getWaypoint(id);
      if (waypoint == null) {
        return;
      }
      Location location = waypoint.getLocation();
      if (location == null) {
        return;
      }
      LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
      keepCurrentLocationVisible = false;
      CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_ZOOM_LEVEL);
      googleMap.moveCamera(cameraUpdate);
    }
  });
}
 
Example #18
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Añade la marca de una Ubicación
 * @param ubicacion
 */
private void marcarUbicacion(Ubicacion ubicacion) {

    // Prepara y añade una nueva marca al mapa
    mapa.addMarker(new MarkerOptions()
            .position(ubicacion.getPosicion())
            .title(ubicacion.getNombre()));

    // Posiciona la vista del usuario en el punto que se acaba de agregar
    CameraUpdate camara =
            CameraUpdateFactory.newLatLng(ubicacion.getPosicion());

    // Coloca la vista del mapa sobre la posición de la gasolinera
    // y activa el zoom para verlo de cerca
    mapa.moveCamera(camara);
    mapa.animateCamera(CameraUpdateFactory.zoomTo(12.0f), 2000, null);
}
 
Example #19
Source File: CameraDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Change the camera position by moving or animating the camera depending on the state of the
 * animate toggle button.
 */
private void changeCamera(CameraUpdate update, CancelableCallback callback) {
    if (animateToggle.isChecked()) {
        if (customDurationToggle.isChecked()) {
            int duration = customDurationBar.getProgress();
            // The duration must be strictly positive so we make it at least 1.
            map.animateCamera(update, Math.max(duration, 1), callback);
        } else {
            map.animateCamera(update, callback);
        }
    } else {
        map.moveCamera(update);
    }
}
 
Example #20
Source File: MapActivity.java    From android-map_list with MIT License 5 votes vote down vote up
public void onMapReady(GoogleMap map) {
    double lat = getIntent().getDoubleExtra(EXTRA_LATITUDE, 0);
    double lng = getIntent().getDoubleExtra(EXTRA_LONGITUDE, 0);

    map.addMarker(new MarkerOptions().position(new LatLng(lat, lng)));

    LatLng coords = new LatLng(lat, lng);
    map.addMarker(new MarkerOptions().position(coords));
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(coords, 10f);
    map.moveCamera(cameraUpdate);
}
 
Example #21
Source File: MainActivity.java    From android-app with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void retrieveBusData(BusData busData) {
    List<Bus> buses = busData.getBuses();
    if (buses == null) {
        Toast.makeText(this, getString(R.string.error_connection_server), Toast.LENGTH_SHORT).show();
        return;
    }
    if (buses.isEmpty()) {
        Toast.makeText(this, getString(R.string.error_bus_404), Toast.LENGTH_SHORT).show();
        return;
    }

    map.clear();

    List<Itinerary> itineraries = busData.getItineraries();
    if(itineraries != null && !itineraries.isEmpty()) {
        for(Itinerary itinerary: itineraries)
            drawItineraryPolyline(itinerary);
    }

    map.setInfoWindowAdapter(new BusInfoWindowAdapter(this));
    MapMarker marker = new MapMarker(map);
    marker.addMarkers(buses);
    LatLngBounds.Builder builder = marker.getBoundsBuilder();

    if (currentLocation != null) {
        LatLng userPosition = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
        mapMarker.markUserPosition(this, userPosition);
        builder.include(userPosition);
    }

    LatLngBounds bounds = builder.build();

    int padding = 100; // offset from edges of the map in pixels
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

    map.moveCamera(cu);
    map.animateCamera(cu);

}
 
Example #22
Source File: MainActivity.java    From Android-GSDemo-GoogleMap with MIT License 5 votes vote down vote up
private void cameraUpdate(){
    LatLng pos = new LatLng(droneLocationLat, droneLocationLng);
    float zoomlevel = (float) 18.0;
    CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(pos, zoomlevel);
    gMap.moveCamera(cu);

}
 
Example #23
Source File: MapLocationViewHolder.java    From android-map_list with MIT License 5 votes vote down vote up
protected void updateMapContents() {
    // Since the mapView is re-used, need to remove pre-existing mapView features.
    mGoogleMap.clear();

    // Update the mapView feature data and camera position.
    mGoogleMap.addMarker(new MarkerOptions().position(mMapLocation.center));

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(mMapLocation.center, 10f);
    mGoogleMap.moveCamera(cameraUpdate);
}
 
Example #24
Source File: MapUiHandler.java    From overpasser with Apache License 2.0 5 votes vote down vote up
private CameraUpdate getCameraUpdate(Location location) {
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(new LatLng(location.getLatitude(), location.getLongitude()))
            .zoom(fragment.zoomLevel)
            .build()
    ;

    return CameraUpdateFactory.newCameraPosition(cameraPosition);
}
 
Example #25
Source File: MapWrapper.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void setBearing(final float aBearing) {
	final CameraPosition position = mGoogleMap.getCameraPosition();
	final CameraPosition newPosition = new CameraPosition(position.target, position.zoom, position.tilt, aBearing);
	final CameraUpdate update = CameraUpdateFactory.newCameraPosition(newPosition);
	mGoogleMap.moveCamera(update);
}
 
Example #26
Source File: MapWrapper.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void setPosition(final IPosition aPosition) {
	final CameraPosition position = mGoogleMap.getCameraPosition();
	final LatLng latLng = new LatLng(aPosition.getLatitude(), aPosition.getLongitude());
	final float bearing = aPosition.hasBearing() ? aPosition.getBearing() : position.bearing;
	final float zoom = aPosition.hasZoomLevel() ? aPosition.getZoomLevel() : position.zoom;
	final CameraPosition newPosition = new CameraPosition(latLng, zoom, position.tilt, bearing);
	final CameraUpdate update = CameraUpdateFactory.newCameraPosition(newPosition);
	mGoogleMap.moveCamera(update);
}
 
Example #27
Source File: MainActivity.java    From NYU-BusTracker-Android with Apache License 2.0 5 votes vote down vote up
private void setUpMapIfNeeded() {
    // First check if GPS is available.
    final LatLng BROADWAY = new LatLng(40.729146, -73.993756);
    int retCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (retCode != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(retCode, this, 1).show();
    }
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        MapFragment mFrag = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
        if (mFrag != null) mMap = mFrag.getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            // The Map is verified. It is now safe to manipulate the map.
            mMap.getUiSettings().setRotateGesturesEnabled(false);
            mMap.getUiSettings().setZoomControlsEnabled(false);
            mMap.setMyLocationEnabled(true);
            mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    return !clickableMapMarkers.get(marker.getId());    // Return true to consume the event.
                }
            });
            CameraUpdate center =
                    CameraUpdateFactory.newLatLng(BROADWAY);
            CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);

            mMap.moveCamera(center);
            mMap.animateCamera(zoom);
        }
    }
}
 
Example #28
Source File: Clusterkraf.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
/**
 * Animate the camera so all of the InputPoint objects represented by the
 * passed ClusterPoint are in view
 * 
 * @param clusterPoint
 */
public void zoomToBounds(ClusterPoint clusterPoint) {
	GoogleMap map = mapRef.get();
	if (map != null && clusterPoint != null) {
		innerCallbackListener.clusteringOnCameraChangeListener.setDirty(System.currentTimeMillis());
		CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(clusterPoint.getBoundsOfInputPoints(), options.getZoomToBoundsPadding());
		map.animateCamera(cameraUpdate, options.getZoomToBoundsAnimationDuration(), null);
	}
}
 
Example #29
Source File: MapViewHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Move the map camera to a specific location
 *
 * @param location new location of camera
 * @param zoom     zoom level
 * @param animated true if movement should be animated, false otherwise
 */
public void moveCamera(LatLng location, float zoom, boolean animated) {
    if (location == null) {
        Log.w("location is null!");
        return;
    }

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, zoom);

    if (animated) {
        googleMap.animateCamera(cameraUpdate);
    } else {
        googleMap.moveCamera(cameraUpdate);
    }
}
 
Example #30
Source File: Clusterkraf.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
/**
 * Show the InfoWindow for the passed Marker and ClusterPoint
 * 
 * @param marker
 * @param clusterPoint
 */
public void showInfoWindow(Marker marker, ClusterPoint clusterPoint) {
	GoogleMap map = mapRef.get();
	if (map != null && marker != null && clusterPoint != null) {
		long dirtyUntil = System.currentTimeMillis() + options.getShowInfoWindowAnimationDuration();
		innerCallbackListener.clusteringOnCameraChangeListener.setDirty(dirtyUntil);
		CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(marker.getPosition());
		map.animateCamera(cameraUpdate, options.getShowInfoWindowAnimationDuration(), new CancelableCallback() {

			@Override
			public void onFinish() {
				innerCallbackListener.handler.post(new Runnable() {

					@Override
					public void run() {
						innerCallbackListener.clusteringOnCameraChangeListener.setDirty(0);

					}
				});
			}

			@Override
			public void onCancel() {
				innerCallbackListener.clusteringOnCameraChangeListener.setDirty(0);
			}
		});
		marker.showInfoWindow();
	}
}