com.google.android.gms.maps.model.CameraPosition Java Examples
The following examples show how to use
com.google.android.gms.maps.model.CameraPosition.
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: CacheDetailActivity.java From Forage with Mozilla Public License 2.0 | 8 votes |
@Override public void onMapReady(GoogleMap googleMap) { googleMap.getUiSettings().setMapToolbarEnabled(false); // Add marker for geocache and move camera LatLng markerPos = new LatLng(location.getLatitude(), location.getLongitude()); googleMap.addMarker(new MarkerOptions() .position(markerPos)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(markerPos) .zoom(13).build(); googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
Example #2
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 6 votes |
private GoogleMap.OnMarkerClickListener createMarkerClickListenerSingle(final Adapter adapter) { return new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { for (int i = 0; i < adapter.getCount(); i++) { CameraPosition cp = adapter.getCameraPosition(i); if (cp != null && cp.target != null && cp.target.latitude == marker.getPosition().latitude && cp.target.longitude == marker.getPosition().longitude) { viewPager.setCurrentItem(i); marker.showInfoWindow(); return true; } } return false; } }; }
Example #3
Source File: CameraDemoActivity.java From android-samples with Apache License 2.0 | 6 votes |
/** * Called when the tilt less button (the one with the \) is clicked. */ public void onTiltLess(View view) { if (!checkReady()) { return; } CameraPosition currentCameraPosition = map.getCameraPosition(); float currentTilt = currentCameraPosition.tilt; float newTilt = currentTilt - 10; newTilt = (newTilt > 0) ? newTilt : 0; CameraPosition cameraPosition = new CameraPosition.Builder(currentCameraPosition) .tilt(newTilt).build(); changeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
Example #4
Source File: MainFragment.java From AndroidSlidingUpPanel-foursquare-map-demo with Apache License 2.0 | 6 votes |
private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = mMapFragment.getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setMyLocationEnabled(false); mMap.getUiSettings().setCompassEnabled(false); mMap.getUiSettings().setZoomControlsEnabled(false); mMap.getUiSettings().setMyLocationButtonEnabled(false); LatLng update = getLastKnownLocation(); if (update != null) { mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(update, 11.0f))); } mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { mIsNeedLocationUpdate = false; moveToLocation(latLng, false); } }); } } }
Example #5
Source File: CameraDemoActivity.java From android-samples with Apache License 2.0 | 6 votes |
/** * Called when the tilt more button (the one with the /) is clicked. */ public void onTiltMore(View view) { if (!checkReady()) { return; } CameraPosition currentCameraPosition = map.getCameraPosition(); float currentTilt = currentCameraPosition.tilt; float newTilt = currentTilt + 10; newTilt = (newTilt > 90) ? 90 : newTilt; CameraPosition cameraPosition = new CameraPosition.Builder(currentCameraPosition) .tilt(newTilt).build(); changeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
Example #6
Source File: MapFragment.java From mage-android with Apache License 2.0 | 6 votes |
@Override public void onChanged(@Nullable Location location) { if (locationChangedListener != null) { locationChangedListener.onLocationChanged(location); } if (locateState == LocateState.FOLLOW) { CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) .zoom(17) .bearing(location.getBearing()) .build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } }
Example #7
Source File: BaseNiboFragment.java From Nibo with MIT License | 6 votes |
/** * Creates a callback for receiving location events. */ private void createLocationCallback() { mLocationCallback = new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); Location location = locationResult.getLastLocation(); if (location != null) { extractGeocode(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) .zoom(15) .build(); mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); handleLocationRetrieval(location); extractGeocode(location.getLatitude(), location.getLongitude()); } } }; }
Example #8
Source File: PTRMapFragment.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
@Override public void onDestroy() { super.onDestroy(); if( mMap == null || mMap.getCameraPosition() == null ) return; CameraPosition cam = mMap.getCameraPosition(); SharedPreferences shared = getActivity().getSharedPreferences( EXTRAS_SHARED_PREFERENCES, 0 ); SharedPreferences.Editor editor = shared.edit(); editor.putLong( SAVED_STATE_LAT, Double.doubleToLongBits( cam.target.latitude ) ); editor.putLong( SAVED_STATE_LONG, Double.doubleToLongBits( cam.target.longitude ) ); editor.putFloat( SAVED_STATE_TILT, cam.tilt ); editor.putFloat( SAVED_STATE_BEARING, cam.bearing ); editor.putFloat( SAVED_STATE_ZOOM, cam.zoom ); editor.commit(); }
Example #9
Source File: MosquesActivity.java From MuslimMateAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onLocationChanged(Location location) { if (location.getLatitude() != 0 || location.getLongitude() != 0) { setFusedLatitude(location.getLatitude()); setFusedLongitude(location.getLongitude()); stopFusedLocation(); CameraPosition oldPos = googleMap.getCameraPosition(); CameraPosition pos = CameraPosition.builder(oldPos) .target(getPosition()) .zoom(zoom) .build(); googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos)); Marker marker = googleMap.addMarker(new MarkerOptions() .position(getPosition()) .title("My Location").icon(BitmapDescriptorFactory.fromResource(R.drawable.placeholder))); AsyncTask placesAsync = new Places().execute(getPosition()); } }
Example #10
Source File: NiboPickerFragment.java From Nibo with MIT License | 6 votes |
protected void addSingleMarkerToMap(LatLng latLng) { if (mMap != null) { if (mCurrentMapMarker != null) { mCurrentMapMarker.remove(); } CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng) .zoom(getDefaultZoom()) .build(); hasWiderZoom = false; mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); mCurrentMapMarker = addMarker(latLng); mMap.setOnMarkerDragListener(this); extractGeocode(latLng.latitude, latLng.longitude); } }
Example #11
Source File: NiboOriginDestinationPickerFragment.java From Nibo with MIT License | 6 votes |
void addOriginMarker(LatLng latLng) { if (mMap != null) { if (mOriginMapMarker != null) { mOriginMapMarker.remove(); mOriginMapMarker = null; } CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng) .zoom(getDefaultZoom()) .build(); hasWiderZoom = false; mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); if (mOriginMarkerPinIconRes != DEFAULT_MARKER_ICON_RES) { mOriginMapMarker = addMarker(latLng, mOriginMarkerPinIconRes); } else { mOriginMapMarker = addMarker(latLng); } mMap.setOnMarkerDragListener(this); showBothMarkersAndGetDirections(); } }
Example #12
Source File: PPTGoogleMapManager.java From react-native-maps with MIT License | 6 votes |
/** * Called repeatedly during any animations or gestures on the map (or once, if the camera is * explicitly set). This may not be called for all intermediate camera positions. It is always * called for the final position of an animation or gesture. * * @param cameraPosition */ @Override public void onCameraChange(CameraPosition cameraPosition) { WritableMap event = Arguments.createMap(); WritableMap data = Arguments.createMap(); data.putDouble("latitude", cameraPosition.target.latitude); data.putDouble("longitude", cameraPosition.target.longitude); data.putDouble("zoom", cameraPosition.zoom); event.putString("event", "didChangeCameraPosition"); event.putMap("data", data); reactContext.getJSModule(RCTEventEmitter.class).receiveEvent( mapView.getId(), "topChange", event ); }
Example #13
Source File: MapLoadFragment.java From Stayfit with Apache License 2.0 | 6 votes |
@Override public void onLocationChanged(Location location) { // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(AskLocationActivity.address1.getLatitude(), AskLocationActivity.address1.getLongitude()); mMap.addMarker(new MarkerOptions().position(sydney).title(AskLocationActivity.place1)); // mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); //move camera when location changed LatLng latLng_Now = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder() .target(sydney) // Sets the center of the map to LatLng (refer to previous snippet) .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(45) // Sets the tilt of the camera to 45 degrees .build(); // Creates a CameraPosition from the builder mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); if (latLng_Prev == null) { latLng_Prev = latLng_Now; } //draw line between two locations: /* Polyline line = mMap.addPolyline(new PolylineOptions() .add(latLng_Prev, latLng_Now) .width(5) .color(Color.RED)); latLng_Prev = latLng_Now;*/ }
Example #14
Source File: PTRMapFragment.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
private void setInitialCameraPosition() { double lng, lat; float tilt, bearing, zoom; SharedPreferences settings = getActivity().getSharedPreferences( EXTRAS_SHARED_PREFERENCES, 0 ); lng = Double.longBitsToDouble( settings.getLong( SAVED_STATE_LONG, Double.doubleToLongBits( mLocationClient.getLastLocation().getLongitude() ) ) ); lat = Double.longBitsToDouble( settings.getLong( SAVED_STATE_LAT, Double.doubleToLongBits( mLocationClient.getLastLocation().getLatitude() ) ) ); zoom = settings.getFloat( SAVED_STATE_ZOOM, 17 ); bearing = settings.getFloat( SAVED_STATE_BEARING, 0 ); tilt = settings.getFloat( SAVED_STATE_TILT, 30 ); CameraPosition cameraPosition = new CameraPosition.Builder() .target( new LatLng( lat, lng) ) .zoom( zoom ) .bearing( bearing ) .tilt( tilt ) .build(); if( cameraPosition == null || mMap == null ) return; mMap.animateCamera( CameraUpdateFactory.newCameraPosition( cameraPosition ) ); }
Example #15
Source File: Venue.java From mConference-Framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void onPostExecute(Void aVoid) { if (status == ConnectionResult.SUCCESS) { // create marker MarkerOptions marker = new MarkerOptions().position( new LatLng(latitude, longitude)).title(venueAddress); // Changing marker icon marker.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_ROSE)); // adding marker googleMap.addMarker(marker); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(latitude, longitude)).zoom(12).build(); googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPosition)); } else { DialogFragment dialogFragment = new PlayServicesUnavailableDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "Play Service Problem"); } }
Example #16
Source File: MovingMarkerActivity.java From Airbnb-Android-Google-Map-View with MIT License | 6 votes |
@Override public void onMapReady(GoogleMap googleMap) { mGoogleMap = googleMap; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } mGoogleMap.setMyLocationEnabled(true); mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { LatLngBounds bounds = mGoogleMap.getProjection().getVisibleRegion().latLngBounds; mAdapter.setBounds(bounds); } }); }
Example #17
Source File: SampleActivity.java From clusterkraf with Apache License 2.0 | 6 votes |
private void initMap() { if (map == null) { SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); if (mapFragment != null) { map = mapFragment.getMap(); if (map != null) { UiSettings uiSettings = map.getUiSettings(); uiSettings.setAllGesturesEnabled(false); uiSettings.setScrollGesturesEnabled(true); uiSettings.setZoomGesturesEnabled(true); map.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { moveMapCameraToBoundsAndInitClusterkraf(); } }); } } } else { moveMapCameraToBoundsAndInitClusterkraf(); } }
Example #18
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 6 votes |
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 #19
Source File: MapWrapper.java From osmdroid with Apache License 2.0 | 5 votes |
@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 #20
Source File: CameraUpdateFactoryImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
@Override public IObjectWrapper newCameraPosition(final CameraPosition cameraPosition) throws RemoteException { Log.d(TAG, "newCameraPosition"); return new ObjectWrapper<CameraUpdate>(new MapPositionCameraUpdate() { @Override MapPosition getMapPosition(Map map) { return GmsMapsTypeHelper.fromCameraPosition(cameraPosition); } }); }
Example #21
Source File: MainActivity.java From ExamplesAndroid with Apache License 2.0 | 5 votes |
@Override public void onLocationChanged(Location location) { mLastLocation = location; if (mCurrLocationMarker != null) { mCurrLocationMarker.remove(); } //MyItem current location marker LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); latitud = location.getLatitude(); longitud = location.getLongitude(); CameraPosition PosicionCamara = CameraPosition.builder() .target(latLng)//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(); mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(PosicionCamara), 6000, null); //move map camera // mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15)); if (mGoogleApiClient != null) { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this); } }
Example #22
Source File: GmsMapsTypeHelper.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
public static MapPosition fromCameraPosition(CameraPosition cameraPosition) { MapPosition mapPosition = new MapPosition(cameraPosition.target.latitude, cameraPosition.target.longitude, fromZoom(cameraPosition.zoom)); mapPosition.setTilt(cameraPosition.tilt); mapPosition.setBearing(fromBearing(cameraPosition.bearing)); return mapPosition; }
Example #23
Source File: MovingMarkerActivity.java From Airbnb-Android-Google-Map-View with MIT License | 5 votes |
private void changeCameraPosition(CameraPosition cameraPosition, boolean animate) { CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition); if (animate) { mGoogleMap.animateCamera(cameraUpdate); } else { mGoogleMap.moveCamera(cameraUpdate); } }
Example #24
Source File: MovingMarkerActivity.java From Airbnb-Android-Google-Map-View with MIT License | 5 votes |
/** * Allows us to navigate to a certain point. */ public void navigateToPoint(LatLng latLng, float tilt, float bearing, float zoom, boolean animate) { CameraPosition position = new CameraPosition.Builder().target(latLng) .zoom(zoom) .bearing(bearing) .tilt(tilt) .build(); changeCameraPosition(position, animate); }
Example #25
Source File: MapWrapper.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean zoomOut() { final CameraPosition cameraPosition = mGoogleMap.getCameraPosition(); final float minZoom = mGoogleMap.getMinZoomLevel(); if (cameraPosition.zoom > minZoom) { mGoogleMap.moveCamera(CameraUpdateFactory.zoomOut()); return true; } return false; }
Example #26
Source File: MapFragment.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
private void initCamera( Location location ) { CameraPosition position = CameraPosition.builder() .target( new LatLng( location.getLatitude(), location.getLongitude() ) ) .zoom( 16f ) .bearing( 0.0f ) .tilt( 0.0f ) .build(); getMap().animateCamera( CameraUpdateFactory.newCameraPosition( position ), null ); getMap().setMapType( MAP_TYPES[curMapTypeIndex] ); getMap().setTrafficEnabled( true ); getMap().setMyLocationEnabled( true ); getMap().getUiSettings().setZoomControlsEnabled( true ); }
Example #27
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 5 votes |
private MarkerOptions createMarkerOptions(CameraPosition cp, String title) { if (cp == null || cp.target == null) return null; return new MarkerOptions() .position(new LatLng(cp.target.latitude, cp.target.longitude)) .title(title) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); }
Example #28
Source File: MyMapView.java From open-location-code with Apache License 2.0 | 5 votes |
@Override public CameraPosition getCameraPosition() { if (mMap == null) { return null; } return mMap.getCameraPosition(); }
Example #29
Source File: MapWrapper.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean zoomIn() { final CameraPosition cameraPosition = mGoogleMap.getCameraPosition(); final float maxZoom = mGoogleMap.getMaxZoomLevel(); if (cameraPosition.zoom < maxZoom) { mGoogleMap.moveCamera(CameraUpdateFactory.zoomIn()); return true; } return false; }
Example #30
Source File: MapUiHandler.java From overpasser with Apache License 2.0 | 5 votes |
private GoogleMap.OnCameraChangeListener getOnCameraChangeListener() { return new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { fragment.zoomLevel = cameraPosition.zoom; } }; }