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

The following examples show how to use com.google.android.gms.maps.CameraUpdateFactory. 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 Project: Forage   Author: Plastix   File: CacheDetailActivity.java    License: Mozilla Public License 2.0 8 votes vote down vote up
@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 Project: FimiX8-RE   Author: wladimir-computin   File: GglMap.java    License: MIT License 7 votes vote down vote up
public void onMapReady(GoogleMap googleMap) {
    this.googleMap = googleMap;
    this.noFlyZone = new GglMapNoFlyZone(googleMap);
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(this.BEIJING, 9.49f));
    if (ContextCompat.checkSelfPermission(this.context, "android.permission.ACCESS_FINE_LOCATION") == 0 || ContextCompat.checkSelfPermission(this.context, "android.permission.ACCESS_COARSE_LOCATION") == 0) {
        googleMap.setMyLocationEnabled(false);
        googleMap.getUiSettings().setMyLocationButtonEnabled(false);
        googleMap.getUiSettings().setCompassEnabled(false);
        googleMap.getUiSettings().setMapToolbarEnabled(false);
        googleMap.getUiSettings().setRotateGesturesEnabled(false);
        this.gglMapLocationManager = new GglMapLocationManager(googleMap, this.context);
        this.aiP2PManager = new GglMapAiPoint2PointManager(this.context, googleMap, this.gglMapLocationManager);
        this.aiSurroundManager = new GglMapAiSurroundManager(this.context, googleMap, this.gglMapLocationManager);
        this.aiLineManager = new GglMapAiLineManager(this.context, googleMap, this.gglMapLocationManager);
        this.gglMapLocationManager.onStart();
        this.isInit = true;
        if (GlobalConfig.getInstance().getMapStyle() == Constants.X8_GENERAL_MAP_STYLE_NORMAL) {
            googleMap.setMapType(1);
        } else if (GlobalConfig.getInstance().getMapStyle() == Constants.X8_GENERAL_MAP_STYLE_SATELLITE) {
            googleMap.setMapType(2);
        }
    }
}
 
Example #3
Source Project: TutosAndroidFrance   Author: florent37   File: MainActivity.java    License: MIT License 7 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {

            googleMap.addMarker(new MarkerOptions().title("Paris").position(PARIS));

            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PARIS, 15));
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

        }
    });
}
 
Example #4
Source Project: roads-api-samples   Author: googlemaps   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(List<SnappedPoint> snappedPoints) {
    mSnappedPoints = snappedPoints;
    mProgressBar.setVisibility(View.INVISIBLE);

    findViewById(R.id.speed_limits).setEnabled(true);

    com.google.android.gms.maps.model.LatLng[] mapPoints =
            new com.google.android.gms.maps.model.LatLng[mSnappedPoints.size()];
    int i = 0;
    LatLngBounds.Builder bounds = new LatLngBounds.Builder();
    for (SnappedPoint point : mSnappedPoints) {
        mapPoints[i] = new com.google.android.gms.maps.model.LatLng(point.location.lat,
                point.location.lng);
        bounds.include(mapPoints[i]);
        i += 1;
    }

    mMap.addPolyline(new PolylineOptions().add(mapPoints).color(Color.BLUE));
    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 0));
}
 
Example #5
Source Project: Nibo   Author: aliumujib   File: NiboPickerFragment.java    License: MIT License 6 votes vote down vote up
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 #6
Source Project: JalanJalan   Author: pratamawijaya   File: AddMapActivity.java    License: Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    if (location == null) {
        // get last location device
        location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if (mMap != null) {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
            mMap.addMarker(new MarkerOptions()
                            .position(new LatLng(location.getLatitude(), location.getLongitude()))
                            .title("Starting Point")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker))
            );
            lat = location.getLatitude();
            lng = location.getLongitude();

            Toast.makeText(this, "Lokasi kamu saat ini, sebagai patokan titik awal perjalanan kamu kak :')", Toast.LENGTH_LONG).show();
        }
    }

}
 
Example #7
Source Project: android-maps-utils   Author: googlemaps   File: CustomMarkerClusteringDemoActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onClusterClick(Cluster<Person> cluster) {
    // Show a toast with some info when the cluster is clicked.
    String firstName = cluster.getItems().iterator().next().name;
    Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();

    // Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
    // inside of bounds, then animate to center of the bounds.

    // Create the builder to collect all essential cluster items for the bounds.
    LatLngBounds.Builder builder = LatLngBounds.builder();
    for (ClusterItem item : cluster.getItems()) {
        builder.include(item.getPosition());
    }
    // Get the LatLngBounds
    final LatLngBounds bounds = builder.build();

    // Animate camera to the bounds
    try {
        getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return true;
}
 
Example #8
Source Project: UberClone   Author: IramML   File: Home.java    License: MIT License 6 votes vote down vote up
private void implementPickupRecyclerView(final ArrayList<Results> results) {
    PlacesAdapter placesAdapter=new PlacesAdapter(this, results, new ClickListener() {
        @Override
        public void onClick(View view, int index) {
            mPlaceLocation=results.get(index).formatted_address;
            etFinalPickup.setText(mPlaceLocation);

            llPickupInput.setVisibility(View.GONE);
            llPickupPlace.setVisibility(View.VISIBLE);
            llDestinationInput.setVisibility(View.GONE);
            llDestinationPlace.setVisibility(View.VISIBLE);

            Double lat=Double.valueOf(results.get(index).geometry.location.lat);
            Double lng=Double.valueOf(results.get(index).geometry.location.lng);
            LatLng latLng=new LatLng(lat, lng);
            if(riderMarket!=null)
                riderMarket.remove();
            riderMarket=mMap.addMarker(new MarkerOptions().position(latLng)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker))
                    .title("Pickup Here"));
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f));
        }
    });
    rvPickupPlaces.setAdapter(placesAdapter);
}
 
Example #9
Source Project: Nibo   Author: aliumujib   File: NiboOriginDestinationPickerFragment.java    License: MIT License 6 votes vote down vote up
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 #10
Source Project: android   Author: codeandcoke   File: Android_Mapas.java    License: 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 #11
Source Project: Track-My-Location   Author: abdularis   File: ShareLocationActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void onLocationUpdated(Location location) {
    String latlng = location.getLatitude() + "/" + location.getLongitude();
    mTextLatLng.setText(latlng);

    LatLng pos = new LatLng(location.getLatitude(), location.getLongitude());
    if (mGoogleMap == null) return;
    if (mMyLocMarker == null) {
        MarkerOptions options = new MarkerOptions().title("Me").position(pos);
        mMyLocMarker = mGoogleMap.addMarker(options);
        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pos, DEFAULT_ZOOM_LEVEL));
    } else {
        mMyLocMarker.setPosition(pos);
        if (mFollowMarker) {
            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(pos));
        } else if (!isLatLngOnVisibleRegion(pos)) {
            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(pos));
        }
    }
}
 
Example #12
Source Project: PhoneProfilesPlus   Author: henrichg   File: LocationGeofenceEditorActivity.java    License: 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 #13
Source Project: AndroidDemoProjects   Author: PaulTR   File: PTRMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
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 #14
Source Project: Taxi-App-Android-XML   Author: dytlabs   File: Home.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
            .getString(R.string.style_json)));

    if (!success) {
        Log.e("Style", "Style parsing failed.");
    }
    LatLng jakarta = new LatLng(-6.232812, 106.820933);
    LatLng southjakarta = new LatLng(-6.22865,106.8151753);
    mMap.addMarker(new MarkerOptions().position(jakarta).icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromView("Set Pickup Location", R.drawable.dot_pickup))));
    mMap.addMarker(new MarkerOptions().position(southjakarta).icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromView("Set Dropoff Location", R.drawable.dot_dropoff))));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(jakarta, 15f));


}
 
Example #15
Source Project: MapsMeasure   Author: j4velin   File: Map.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    try {
        metric = savedInstanceState.getBoolean("metric");
        @SuppressWarnings("unchecked")
        // Casting to Stack<LatLng> apparently results in
                // "java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Stack"
                // on some devices
                List<LatLng> tmp = (List<LatLng>) savedInstanceState.getSerializable("trace");
        Iterator<LatLng> it = tmp.iterator();
        while (it.hasNext()) {
            addPoint(it.next());
        }
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(savedInstanceState.getDouble("position-lat"),
                        savedInstanceState.getDouble("position-lon")),
                savedInstanceState.getFloat("position-zoom")));
    } catch (Exception e) {
        if (BuildConfig.DEBUG) Logger.log(e);
        e.printStackTrace();
    }
}
 
Example #16
Source Project: android   Author: codeandcoke   File: Mapa.java    License: 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 #17
Source Project: mConference-Framework   Author: BuildmLearn   File: Venue.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #18
Source Project: android-maps-utils   Author: googlemaps   File: CustomMarkerClusteringDemoActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 9.5f));
    }

    mClusterManager = new ClusterManager<>(this, getMap());
    mClusterManager.setRenderer(new PersonRenderer());
    getMap().setOnCameraIdleListener(mClusterManager);
    getMap().setOnMarkerClickListener(mClusterManager);
    getMap().setOnInfoWindowClickListener(mClusterManager);
    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterInfoWindowClickListener(this);
    mClusterManager.setOnClusterItemClickListener(this);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);

    addItems();
    mClusterManager.cluster();
}
 
Example #19
Source Project: MuslimMateAndroid   Author: fekracomputers   File: MosquesActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 #20
Source Project: journaldev   Author: journaldev   File: MainActivity.java    License: 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 #21
Source Project: mollyim-android   Author: mollyim   File: PlacePickerActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void moveMapToInitialIfPossible() {
  if (initialLocation != null && googleMap != null) {
    Log.d(TAG, "Moving map to initial location");
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLocation, ZOOM));
    setCurrentLocation(initialLocation);
  }
}
 
Example #22
Source Project: mollyim-android   Author: mollyim   File: SignalMapView.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ListenableFuture<Bitmap> display(final SignalPlace place) {
  final SettableFuture<Bitmap> future = new SettableFuture<>();

  this.mapView.onCreate(null);
  this.mapView.onResume();

  this.mapView.setVisibility(View.VISIBLE);
  this.imageView.setVisibility(View.GONE);

  this.mapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(final GoogleMap googleMap) {
      googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
      googleMap.addMarker(new MarkerOptions().position(place.getLatLong()));
      googleMap.setBuildingsEnabled(true);
      googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      googleMap.getUiSettings().setAllGesturesEnabled(false);
      googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
          googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
            @Override
            public void onSnapshotReady(Bitmap bitmap) {
              future.set(bitmap);
              imageView.setImageBitmap(bitmap);
              imageView.setVisibility(View.VISIBLE);
              mapView.setVisibility(View.GONE);
              mapView.onPause();
              mapView.onDestroy();
            }
          });
        }
      });
    }
  });

  this.textView.setText(place.getDescription());

  return future;
}
 
Example #23
Source Project: FimiX8-RE   Author: wladimir-computin   File: GglMapLocationManager.java    License: MIT License 5 votes vote down vote up
public void onLocationResult(LocationResult result) {
    if (this.locationMarker != null) {
        onLocationChanged(result.getLastLocation());
    } else if (result.getLastLocation() != null) {
        LatLng latLng = new LatLng(result.getLastLocation().getLatitude(), result.getLastLocation().getLongitude());
        this.locationMarker = this.mGoogleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.location_map)).anchor(0.5f, 0.5f));
        this.mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.555f));
    }
}
 
Example #24
Source Project: ScreenshotsNanny   Author: thyrlian   File: MapsActivity.java    License: 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 #25
Source Project: Airbnb-Android-Google-Map-View   Author: SkyTreasure   File: GoogleMapUtis.java    License: 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 #26
Source Project: AndroidSlidingUpPanel-foursquare-map-demo   Author: dlukashev   File: MainFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void collapseMap() {
    if (mHeaderAdapter != null) {
        mHeaderAdapter.showSpace();
    }
    mTransparentView.setVisibility(View.GONE);
    if (mMap != null && mLocation != null) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLocation, 11f), 1000, null);
    }
    mListView.setScrollingEnabled(true);
}
 
Example #27
Source Project: kute   Author: scorelab   File: LandActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
    mGoogleMap.animateCamera(cameraUpdate);
    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 permission requests
        return;
    }
    locationManager.removeUpdates(this);
}
 
Example #28
Source Project: google-maps-clustering   Author: sharewire   File: MapsActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(final GoogleMap googleMap) {
    googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(NETHERLANDS, 0));
        }
    });

    ClusterManager<SampleClusterItem> clusterManager = new ClusterManager<>(this, googleMap);
    clusterManager.setCallbacks(new ClusterManager.Callbacks<SampleClusterItem>() {
        @Override
        public boolean onClusterClick(@NonNull Cluster<SampleClusterItem> cluster) {
            Log.d(TAG, "onClusterClick");
            return false;
        }

        @Override
        public boolean onClusterItemClick(@NonNull SampleClusterItem clusterItem) {
            Log.d(TAG, "onClusterItemClick");
            return false;
        }
    });
    googleMap.setOnCameraIdleListener(clusterManager);

    List<SampleClusterItem> clusterItems = new ArrayList<>();
    for (int i = 0; i < 20000; i++) {
        clusterItems.add(new SampleClusterItem(
                RandomLocationGenerator.generate(NETHERLANDS)));
    }
    clusterManager.setItems(clusterItems);
}
 
Example #29
Source Project: journaldev   Author: journaldev   File: MapsActivity.java    License: MIT License 5 votes vote down vote up
/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

    setMapStyle();


}
 
Example #30
Source Project: SEAL-Demo   Author: microsoft   File: HomeFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    List<Location> locationList = locationResult.getLocations();
    if (!locationList.isEmpty()) {
        Location location = locationList.get(locationList.size() - 1);
        Log.i(TAG, "Location: " + location.getLatitude() + " " + location.getLongitude());
        //Place current location marker
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, MAP_ZOOM));
    }
}