Java Code Examples for com.google.android.gms.maps.CameraUpdateFactory#newLatLngZoom()

The following examples show how to use com.google.android.gms.maps.CameraUpdateFactory#newLatLngZoom() . 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: MapFragment.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationFromGoogleServicesResult(Location location) {
    if(!mapCameraLocationInitialized) {

        mapCameraLocation = new LatLng(location.getLatitude(), location.getLongitude());

        mapCameraLocationInitialized = true;

        if(map!=null){
            mapCameraUpdateAnimation = CameraUpdateFactory.newLatLngZoom(
                    mapCameraLocation, mapCameraZoom);
            map.moveCamera(mapCameraUpdateAnimation);
        }
    }

}
 
Example 2
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 3
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 4
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 5
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 6
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 5 votes vote down vote up
/**
 * Sets the user's location marker, if it has been enabled.
 *
 * @param map
 * @param cameraPosition
 */
@ReactProp(name = "cameraPosition")
public void setCameraPosition(MapView map, ReadableMap cameraPosition) {
    float zoom = (float) cameraPosition.getDouble("zoom");

    if (cameraPosition.hasKey("auto") && cameraPosition.getBoolean("auto")) {
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        if (location == null) {
            return;
        }

        cameraUpdate = CameraUpdateFactory.newLatLngZoom(
                new LatLng(location.getLatitude(), location.getLongitude()),
                zoom
        );

        map.getMapAsync(this);
    } else {
        cameraUpdate = CameraUpdateFactory.newLatLngZoom(
                new LatLng(
                        cameraPosition.getDouble("latitude"),
                        cameraPosition.getDouble("longitude")
                ), zoom
        );

        map.getMapAsync(this);
    }
}
 
Example 7
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 8
Source File: LocationActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
        case R.id.map_list_menu_map:
            if (googleMap != null) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            }
            break;
        case R.id.map_list_menu_satellite:
            if (googleMap != null) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            }
            break;
        case R.id.map_list_menu_hybrid:
            if (googleMap != null) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            }
            break;
        case R.id.map_to_my_location:
            if (myLocation != null) {
                LatLng latLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
                if (googleMap != null) {
                    CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
                    googleMap.animateCamera(position);
                }
            }
            break;
        case android.R.id.home:
            finishFragment();
            break;
    }
    return true;
}
 
Example 9
Source File: LandActivity.java    From kute with 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 10
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 11
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 12
Source File: GeoPointMapActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void animateToPoint(double lat, double lng, float accuracy) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int screenSize = Math.min(metrics.widthPixels, metrics.heightPixels);
    int zoomLevel = calculateZoomLevel(screenSize, accuracy);

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), zoomLevel);
    map.animateCamera(cameraUpdate);
}
 
Example 13
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 14
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 15
Source File: MainActivity.java    From video-tutorial-code with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onClick_Burnaby(View v) {
	map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
	CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 14);
	map.animateCamera(update);
	
}
 
Example 16
Source File: MainActivity.java    From video-tutorial-code with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onClick_Surrey(View v) {
	map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
	CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_SURRREY, 16);
	map.animateCamera(update);
	
}
 
Example 17
Source File: MainActivity.java    From video-tutorial-code with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onClick_City(View v) {
//		CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
		map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
		CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 9);
		map.animateCamera(update);
	}
 
Example 18
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());
    }

}