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

The following examples show how to use com.google.android.gms.maps.GoogleMap#moveCamera() . 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 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 File: MapsMarkerActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Manipulates the map when it's available.
 * The API invokes this callback 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 receives a prompt to install
 * Play services inside the SupportMapFragment. The API invokes this method after the user has
 * installed Google Play services and returned to the app.
 */
// [END_EXCLUDE]
// [START maps_marker_on_map_ready_add_marker]
@Override
public void onMapReady(GoogleMap googleMap) {
    // [START_EXCLUDE silent]
    // Add a marker in Sydney, Australia,
    // and move the map's camera to the same location.
    // [END_EXCLUDE]
    LatLng sydney = new LatLng(-33.852, 151.211);
    googleMap.addMarker(new MarkerOptions()
        .position(sydney)
        .title("Marker in Sydney"));
    // [START_EXCLUDE silent]
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    // [END_EXCLUDE]
}
 
Example 3
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 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
    googleMap.addMarker(new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_android))//Modificamos el icono,este recurso se encuentra en la carpeta mipmap
            .anchor(0.0f, 1.0f) // Indicamos el lugar donde se fijara: Izq -Inferior en este caso
            .position(lugar));//Indicamos la posicion o "lugar"

}
 
Example 4
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    // Add a marker in Sydney, Australia, and move the camera.

    LatLng lugar = new LatLng(19.4112431, -99.2091994);//creamos una #localizacion#
    googleMap.addMarker(new MarkerOptions().position(lugar).title("Saludos desde Mexico"));//creamos una marca en el mapa "lugar"
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(lugar));//Movemos la camara en la localizacion "lugar" asignado

    //Formas de visualizar un mapa
    // MAP_TYPE_TERRAIN, MAP_TYPE_HYBRID y  MAP_TYPE_NONE

    // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);//Vista sin mapa
    //googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);//Vista Normal
    googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);//Vista Satelital
    //googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);//Vista Terreno
    //googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);//Vista Hibrida
}
 
Example 5
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {

    //Creamos una localizacion
    LatLng lugar = new LatLng(19.3910038, -99.2837004);//creamos el punto de partida(DF)


   //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, 20));


    // Indicamos los puntos para crear la polilinea
    //Ente este caso la ruta es del df - Guerrero - Michoacan y llegando a Guadalajara
    googleMap.addPolyline(new PolylineOptions().geodesic(true)
            .add(new LatLng(17.547789, -99.532435))  // Guerrero
            .add(new LatLng(19.1539267, -103.0220045))  // Michoacan
            .add(new LatLng(20.6998812, -103.405454))  // Guadalajara
            );
    //Utilidad para generar polilineas de google
    //https://developers.google.com/maps/documentation/utilities/polylineutility
}
 
Example 6
Source File: AbstractDetailActivity.java    From google-io-2014-compat with Apache License 2.0 6 votes vote down vote up
private void setupMap() {
    final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    double lat = getIntent().getDoubleExtra("lat", 37.6329946);
    double lng = getIntent().getDoubleExtra("lng", -122.4938344);
    float zoom = getIntent().getFloatExtra("zoom", 15);

    LatLng position = new LatLng(lat, lng);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
    map.addMarker(new MarkerOptions().position(position));

    // We need the snapshot of the map to prepare the shader for the circular reveal.
    // So the map is visible on activity start and then once the snapshot is taken, quickly hidden.
    map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            map.snapshot(new GoogleMap.SnapshotReadyCallback() {
                @Override
                public void onSnapshotReady(Bitmap bitmap) {
                    mapLoaded(bitmap);
                }
            });
        }
    });
}
 
Example 7
Source File: FenceRecyclerAdapter.java    From JCVD with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.setMyLocationEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(false);

    StorableLocationFence locFence = null;
    if (!mFence.getAndFences().isEmpty()) {
        for (StorableFence andFence : mFence.getAndFences()) {
            if (andFence.getType().equals(StorableFence.Type.LOCATION)) {
                locFence = (StorableLocationFence) andFence;
            }
        }
    } else {
        if (mFence.getType().equals(StorableFence.Type.LOCATION)) {
            locFence = (StorableLocationFence) mFence;
        }
    }
    if (locFence != null) {
        LatLng latLng = new LatLng(locFence.getLatitude(), locFence.getLongitude());
        CircleOptions circleOptions = new CircleOptions()
                .center(latLng)
                .radius(locFence.getRadius()); // In meters

        googleMap.addCircle(circleOptions);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(latLng)
                .zoom(14)
                .build();
        googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
}
 
Example 8
Source File: GroundOverlayDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    // Register a listener to respond to clicks on GroundOverlays.
    map.setOnGroundOverlayClickListener(this);

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));

    images.clear();
    images.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922));
    images.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny));

    // Add a small, rotated overlay that is clickable by default
    // (set by the initial state of the checkbox.)
    groundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions()
            .image(images.get(1)).anchor(0, 1)
            .position(NEAR_NEWARK, 4300f, 3025f)
            .bearing(30)
            .clickable(((CheckBox) findViewById(R.id.toggleClickability)).isChecked()));

    // Add a large overlay at Newark on top of the smaller overlay.
    groundOverlay = map.addGroundOverlay(new GroundOverlayOptions()
            .image(images.get(currentEntry)).anchor(0, 1)
            .position(NEWARK, 8600f, 6500f));

    transparencyBar.setOnSeekBarChangeListener(this);

    // Override the default content description on the view, for accessibility mode.
    // Ideally this string would be localised.
    map.setContentDescription("Google Map with ground overlay.");
}
 
Example 9
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 10
Source File: MapDialogFragment.java    From openshop.io-android with MIT License 5 votes vote down vote up
@Override
    public void onMapReady(GoogleMap googleMap) {
        if (branch != null && branch.getCoordinates() != null) {
            LatLng position = new LatLng(branch.getCoordinates().getLat(), branch.getCoordinates().getLon());
            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 13));
            googleMap.addMarker(new MarkerOptions()
//                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.shop_info_map_mrker))
                    .title(branch.getName())
                    .snippet(branch.getAddress())
                    .position(position)
                    .draggable(false)
                    .anchor((float) 0.917, (float) 0.903));
        }
    }
 
Example 11
Source File: MapActivity.java    From snazzymaps-browser with Apache License 2.0 5 votes vote down vote up
/**
 * Styles the map when its available, using the style JSON provided by the
 * previous activity.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        mStyle = new SnazzyMapsStyle(bundle.getString(JSON_ID));
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(START_LATLNG, 11));
        mStyle.applyToMap(googleMap);
        getSupportActionBar().setTitle(mStyle.name);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);  // Back button in action bar.
    }
}
 
Example 12
Source File: DetailActivity.java    From google-io-2014 with Apache License 2.0 5 votes vote down vote up
private void setupMap() {
    GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    double lat = getIntent().getDoubleExtra("lat", 37.6329946);
    double lng = getIntent().getDoubleExtra("lng", -122.4938344);
    float zoom = getIntent().getFloatExtra("zoom", 15.0f);

    LatLng position = new LatLng(lat, lng);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
    map.addMarker(new MarkerOptions().position(position));
}
 
Example 13
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 14
Source File: ObservationFormPickerActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(final GoogleMap map) {
    ObservationLocation location = getIntent().getParcelableExtra(ObservationEditActivity.LOCATION);
    Point centroid = location.getCentroid();
    LatLng latLng = new LatLng(centroid.getY(), centroid.getX());

    float zoom = getIntent().getFloatExtra(ObservationEditActivity.INITIAL_ZOOM, 0);

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));

}
 
Example 15
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, 30));
}
 
Example 16
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    // Add a marker in Sydney, Australia, and move the camera.

    LatLng lugar = new LatLng(19.4112431, -99.2091994);//creamos una #localizacion#
    googleMap.addMarker(new MarkerOptions().position(lugar).title("Saludos desde Mexico"));//creamos una marca en el mapa "lugar"
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(lugar));//Movemos la camara en la localizacion "lugar" asignado

}
 
Example 17
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 4 votes vote down vote up
/**
 * Event handler for when map is ready to receive update parameters.
 *
 * @param googleMap
 */
@Override
public void onMapReady(GoogleMap googleMap) {

    // Clear previous map if already there
    googleMap.clear();

    UiSettings settings = googleMap.getUiSettings();

    // Set location based flags
    if (locationManager != null) {
        settings.setMyLocationButtonEnabled(this.myLocationButton);
        googleMap.setMyLocationEnabled(this.showsUserLocation);
    }

    // Set all other flags
    settings.setScrollGesturesEnabled(this.scrollGestures);
    settings.setZoomGesturesEnabled(this.zoomGestures);
    settings.setTiltGesturesEnabled(this.tiltGestures);
    settings.setRotateGesturesEnabled(this.rotateGestures);
    settings.setCompassEnabled(this.compassButton);

    // Update the camera position
    if (cameraUpdate != null) {
        googleMap.moveCamera(cameraUpdate);
    }

    // Add the markers
    addMapMarkers(googleMap);
    googleMap.setOnMarkerClickListener(this);

    // Attach the event handlers
    if (firstMapReady) {
        googleMap.setOnCameraChangeListener(this);
        googleMap.setOnMapClickListener(this);
        googleMap.setOnMapLongClickListener(this);
        googleMap.setOnMarkerDragListener(this);
        googleMap.setOnMyLocationButtonClickListener(this);

        firstMapReady = false;
    }
}
 
Example 18
Source File: PolySimplifyDemoActivity.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    GoogleMap map = getMap();

    // Original line
    List<LatLng> line = PolyUtil.decode(LINE);
    map.addPolyline(new PolylineOptions()
            .addAll(line)
            .color(Color.BLACK));

    if (!isRestore) {
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
    }

    List<LatLng> simplifiedLine;

    /*
     * Simplified lines - increasing the tolerance will result in fewer points in the simplified
     * line
     */
    double tolerance = 5; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.RED - ALPHA_ADJUSTMENT));

    tolerance = 20; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.GREEN - ALPHA_ADJUSTMENT));

    tolerance = 50; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.MAGENTA - ALPHA_ADJUSTMENT));

    tolerance = 500; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.YELLOW - ALPHA_ADJUSTMENT));

    tolerance = 1000; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.BLUE - ALPHA_ADJUSTMENT));


    // Triangle polygon - the polygon should be closed
    ArrayList<LatLng> triangle = new ArrayList<>();
    triangle.add(new LatLng(28.06025,-82.41030));  // Should match last point
    triangle.add(new LatLng(28.06129,-82.40945));
    triangle.add(new LatLng(28.06206,-82.40917));
    triangle.add(new LatLng(28.06125,-82.40850));
    triangle.add(new LatLng(28.06035,-82.40834));
    triangle.add(new LatLng(28.06038, -82.40924));
    triangle.add(new LatLng(28.06025,-82.41030));  // Should match first point

    map.addPolygon(new PolygonOptions()
            .addAll(triangle)
            .fillColor(Color.BLUE - ALPHA_ADJUSTMENT)
            .strokeColor(Color.BLUE)
            .strokeWidth(5));

    // Simplified triangle polygon
    tolerance = 88; // meters
    List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
    map.addPolygon(new PolygonOptions()
            .addAll(simplifiedTriangle)
            .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT)
            .strokeColor(Color.YELLOW)
            .strokeWidth(5));

    // Oval polygon - the polygon should be closed
    List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
    map.addPolygon(new PolygonOptions()
            .addAll(oval)
            .fillColor(Color.BLUE - ALPHA_ADJUSTMENT)
            .strokeColor(Color.BLUE)
            .strokeWidth(5));

    // Simplified oval polygon
    tolerance = 10; // meters
    List simplifiedOval= PolyUtil.simplify(oval, tolerance);
    map.addPolygon(new PolygonOptions()
            .addAll(simplifiedOval)
            .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT)
            .strokeColor(Color.YELLOW)
            .strokeWidth(5));
}
 
Example 19
Source File: MapFragment.java    From GNSS_Compare with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {

    this.map = map;

    mapCameraUpdateAnimation = CameraUpdateFactory.newLatLngZoom(
            mapCameraLocation, mapCameraZoom);

    map.moveCamera(mapCameraUpdateAnimation);

    for(Map.Entry<CalculationModule, MapDataSeries> entry: dataSeries.entrySet()){
        entry.getValue().resetMarkers();
        addLocationSource(entry.getValue());
    }

}
 
Example 20
Source File: DetailFragment.java    From animation-samples with Apache License 2.0 4 votes vote down vote up
private void initializeMap(final GoogleMap googleMap) {
    googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(mCameraPosition));
    googleMap.setOnMapLoadedCallback(getOnMapLoadedCallback(googleMap));
    setMarkers(googleMap);
}