Java Code Examples for com.google.android.gms.maps.GoogleMap#animateCamera()

The following examples show how to use com.google.android.gms.maps.GoogleMap#animateCamera() . 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: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {

  googleMap.addMarker(new MarkerOptions()
          .position(new LatLng(37.4233438, -122.0728817))
          .title("LinkedIn")
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

    googleMap.addMarker(new MarkerOptions()
            .position(new LatLng(37.4629101,-122.2449094))
            .title("Facebook")
            .snippet("Facebook HQ: Menlo Park"));

    googleMap.addMarker(new MarkerOptions()
            .position(new LatLng(37.3092293, -122.1136845))
            .title("Apple"));

    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.4233438, -122.0728817), 10));

}
 
Example 2
Source File: GoogleMapUtis.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
public static void fixZoomForMarkers(GoogleMap googleMap, List<Marker> markers) {
	if (markers!=null && markers.size() > 0) {
	    LatLngBounds.Builder bc = new LatLngBounds.Builder();

	    for (Marker marker : markers) {
	        bc.include(marker.getPosition());
	    }

	    googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null);
	}
}
 
Example 3
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();
	}
}
 
Example 4
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 5
Source File: SaveStateDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    MarkerOptions markerOptions = new MarkerOptions()
            .position(mMarkerPosition)
            .icon(BitmapDescriptorFactory.defaultMarker(mMarkerInfo.mHue))
            .draggable(true);
    map.addMarker(markerOptions);
    map.setOnMarkerDragListener(this);
    map.setOnMarkerClickListener(this);

    if (mMoveCameraToMarker) {
        map.animateCamera(CameraUpdateFactory.newLatLng(mMarkerPosition));
    }
}
 
Example 6
Source File: MapsActivity.java    From ScreenshotsNanny with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    LatLng berlin = new LatLng(mBerlinLat, mBerlinLng);
    Marker marker = googleMap.addMarker(new MarkerOptions().position(berlin).title(getString(R.string.map_marker_title)));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(berlin));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(mBerlinZoomLevel));
    mEditTextLat.setText(String.valueOf(marker.getPosition().latitude));
    mEditTextLng.setText(String.valueOf(marker.getPosition().longitude));
}
 
Example 7
Source File: MapsActivity.java    From LearningAppAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configures the google map
 * In case there is GeoLocations or Beacons
 *
 * @param map Google map to work on
 */
private void setUpMap(GoogleMap map) {
    MCLocationManager lm = MCLocationManager.getInstance();

    /* lastCoordinate is the location which the map will show, the default being San Francisco */
    LatLng lastCoordinate = new LatLng(Double.parseDouble(getResources().getString(R.string.default_latitude)),
            Double.parseDouble(getResources().getString(R.string.default_longitude)));

    /* Loops through the beacons and set them in the map */
    for (MCBeacon beacon : lm.getBeacons()) {
        map.addMarker(new MarkerOptions()
                .position(beacon.getCoordenates())
                .title(beacon.getName())
                .icon(BitmapDescriptorFactory.fromResource((R.drawable.tags))));
        map.addCircle(new CircleOptions()
                .center(beacon.getCoordenates())
                .radius(beacon.getRadius())
                .strokeColor(getResources().getColor(R.color.beaconOuterCircle))
                .fillColor(getResources().getColor(R.color.beaconInnerCircle)));
        lastCoordinate = beacon.getCoordenates();
    }

    /* Loops through the locations and set them in the map */
    for (MCGeofence location : lm.getGeofences()) {
        map.addMarker(new MarkerOptions().position(location.getCoordenates()).title(location.getName()));
        map.addCircle(new CircleOptions()
                .center(location.getCoordenates())
                .radius(location.getRadius())
                .strokeColor(getResources().getColor(R.color.geoLocationOuterCircle))
                .fillColor(getResources().getColor(R.color.geoLocationInnerCircle)));
        lastCoordinate = location.getCoordenates();
    }
    /* Centers the map in the last coordinate found and sets the zoom */
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(lastCoordinate).zoom(getResources().getInteger(R.integer.map_zoom)).build();
    map.animateCamera(CameraUpdateFactory
            .newCameraPosition(cameraPosition));
}
 
Example 8
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {

    //Creamos una localizacion
    LatLng lugar = new LatLng(19.4352007, -99.1550963);//creamos una #localizacion#


   //Movemos la camara,El metodo newLatLngZoom esta sobrecargado
    //Este es uno de los metodos,y recibe una localizacion y el respectivo zoom como segundo parametro
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lugar, 18));

    //Agregamos un marcado personalizado
    // Marcadores planas girarán cuando el mapa se gira,
    //Y el cambio en perspectiva cuando el mapa se inclina..
    googleMap.addMarker(new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_android))//Modificamos el icono,este recurso se encuentra en la carpeta mipmap
            .position(lugar)//Indicamos la posicion
            .flat(true)
            .rotation(360));//Rotacion

    //Mas parametros aqui: https://developers.google.com/android/reference/com/google/android/gms/maps/model/CameraPosition
    CameraPosition PosicionCamara = CameraPosition.builder()
            .target(lugar)//Direccion de la camara
            .zoom(20)//Zoom al mapa
            .bearing(90)//Dirección que la cámara está apuntando en, en grados en sentido horario desde el norte.
            .build();


    //Mas informacion de animateCamera:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
    // Animar el cambio en la vista de la cámara en  9 segundos
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(
                    PosicionCamara),//Indicamos lka posicion de la camara
                     9000,//Indicamos el tiempo que tardara en rotar(9 segundos)
                        null);

}
 
Example 9
Source File: DetailFragment.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
@NonNull
private GoogleMap.OnMapLoadedCallback getOnMapLoadedCallback(final GoogleMap googleMap) {
    return new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            googleMap.getUiSettings().setMapToolbarEnabled(false);
            if (mGallery.hasDetails()) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                googleMap.animateCamera(
                        CameraUpdateFactory.newLatLngBounds(mGallery.getBounds(), mMapPadding));
            }
        }
    };
}
 
Example 10
Source File: GoogleMapUtis.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
public static void fixZoomForLatLngs(GoogleMap googleMap, List<LatLng> latLngs) {
	if (latLngs!=null && latLngs.size() > 0) {
	    LatLngBounds.Builder bc = new LatLngBounds.Builder();

	    for (LatLng latLng: latLngs) {
	        bc.include(latLng);
	    }

	    googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null);
	}
}
 
Example 11
Source File: EmergencyInteractorImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void animateMarketToTop(GoogleMap map, Marker marker, double mapHeight) {
    double dpPerdegree = 256.0 * Math.pow(2, 15) / 170.0;
    double screen_height_30p = 15.0 * mapHeight / 100.0;
    double degree_30p = screen_height_30p / dpPerdegree;
    LatLng latLng = marker.getPosition();
    LatLng centerlatlng = new LatLng(latLng.latitude - degree_30p, latLng.longitude);
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerlatlng, 15), 500, null);
}
 
Example 12
Source File: EmergencyInteractorImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void animateCameraToAllEstablishments(GoogleMap mMap) {
    if (mMap != null) {
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        for (Marker marker : mDeviceMarkerHash.values()) {
            builder.include(marker.getPosition());
        }
        LatLngBounds bounds = builder.build();

        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
    }
}
 
Example 13
Source File: EstablishmentInteractorImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void animateMarketToTop(GoogleMap map, Marker marker, double mapHeight) {
    double dpPerdegree = 256.0 * Math.pow(2, 15) / 170.0;
    double screen_height_30p = 15.0 * mapHeight / 100.0;
    double degree_30p = screen_height_30p / dpPerdegree;
    LatLng latLng = marker.getPosition();
    LatLng centerlatlng = new LatLng(latLng.latitude - degree_30p, latLng.longitude);
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerlatlng, 15), 500, null);
}
 
Example 14
Source File: EstablishmentInteractorImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void animateCameraToAllEstablishments(GoogleMap mMap) {
    if (mMap != null) {
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        for (Marker marker : mDeviceMarkerHash.values()) {
            builder.include(marker.getPosition());
        }
        LatLngBounds bounds = builder.build();

        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
    }
}
 
Example 15
Source File: Maps.java    From aware with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.setMyLocationEnabled(true);
    map.setTrafficEnabled(false);
    map.setIndoorEnabled(false);
    map.setBuildingsEnabled(false);
    map.getUiSettings().setZoomControlsEnabled(true);


    final CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(21, 78));
    CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);

    map.moveCamera(center);
    map.animateCamera(zoom);

    GPSTracker tracker = new GPSTracker(activity);
    if (!tracker.canGetLocation()) {
        tracker.showSettingsAlert();

    } else {
        latitude = tracker.getLatitude();
        longitude = tracker.getLongitude();
        LatLng coordinate = new LatLng(latitude, longitude);
        CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 5);
        map.animateCamera(yourLocation);

    }

    this.map = map;

}
 
Example 16
Source File: EmergencyInteractorImpl.java    From Saude-no-Mapa with MIT License 4 votes vote down vote up
@Override
public void animateCameraToMarker(GoogleMap mMap, Marker marker) {
    mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()), 500, null);
}
 
Example 17
Source File: ProfileActivity.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
	map.setMapType(preferences.getInt(getString(R.string.baseLayerKey), getResources().getInteger(R.integer.baseLayerDefaultValue)));

	int dayNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
	if (dayNightMode == Configuration.UI_MODE_NIGHT_NO) {
		map.setMapStyle(null);
	} else {
		map.setMapStyle(MapStyleOptions.loadRawResourceStyle(getApplicationContext(), R.raw.map_theme_night));
	}


	if (latLng != null && icon != null) {
		map.addMarker(new MarkerOptions()
			.position(latLng)
			.icon(icon));

		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null) {
			float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());

			int color = LocationBitmapFactory.locationColor(getApplicationContext(), location);
			map.addCircle(new CircleOptions()
				.center(latLng)
				.radius(accuracy)
				.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
				.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
				.strokeWidth(2.0f));

			double latitudePadding = (accuracy / 111325);
			LatLngBounds bounds = new LatLngBounds(
					new LatLng(latLng.latitude - latitudePadding, latLng.longitude),
					new LatLng(latLng.latitude + latitudePadding, latLng.longitude));

			int minDimension = Math.min(mapView.getWidth(), mapView.getHeight());
			int padding = (int) Math.floor(minDimension / 5f);
			map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
		} else {
			map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
		}
	}
}
 
Example 18
Source File: RMBTMapFragment.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v)
{
    final FragmentManager fm = ((FragmentActivity) getActivity()).getSupportFragmentManager();
    final FragmentTransaction ft;
    
    final GoogleMap map = getMap();

    switch (v.getId())
    {

    case R.id.mapChooseButton:

        ft = fm.beginTransaction();
        final RMBTMapFilterFragment mapFilterFragment = new RMBTMapFilterFragment();
        ft.replace(R.id.fragment_content, mapFilterFragment, "map_filter");
        ft.addToBackStack("map_filter");
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
        
        break;

    case R.id.mapLocateButton:

        if (map != null && geoLocation != null)
        {
            final Location location = geoLocation.getLastKnownLocation();
            if (location != null)
            {
                final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
            }
        }
        break;

    case R.id.mapHelpButton:
        ((RMBTMainActivity) getActivity()).showHelp("", false, AppConstants.PAGE_TITLE_HELP); // TODO: put correct
                                                    // help url
        break;

    case R.id.mapZoomInButton:

        if (map != null)
            map.animateCamera(CameraUpdateFactory.zoomIn());

        break;

    case R.id.mapZoomOutButton:

        if (map != null)
            map.animateCamera(CameraUpdateFactory.zoomOut());

        break;

    case R.id.mapLocationSearchButton:
    	
    	if (map != null) {
    		MapLocationSearch.showDialog(this);
    	}
    	
    	break;
        
    default:
        break;
    }

}