Search in sources :

Example 16 with CameraUpdate

use of com.google.android.gms.maps.CameraUpdate in project cw-omnibus by commonsguy.

the class MainActivity method onMapReady.

@Override
public void onMapReady(final GoogleMap map) {
    if (needsInit) {
        CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044, -73.98180484771729));
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
        map.moveCamera(center);
        map.animateCamera(zoom);
    }
    addMarkers(map);
    map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater(), models));
    map.setOnInfoWindowClickListener(this);
}
Also used : LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 17 with CameraUpdate

use of com.google.android.gms.maps.CameraUpdate in project Ushahidi_Android by ushahidi.

the class BaseMapFragment method updateMarker.

protected void updateMarker(LatLng point, boolean center) {
    if (map != null) {
        if (updatableMarker == null) {
            CameraUpdate p = CameraUpdateFactory.newLatLng(point);
            map.moveCamera(p);
            updatableMarker = createUpdatableMarker(point);
        } else {
            updatableMarker.update(point);
        }
        if (center) {
            CameraUpdate c = CameraUpdateFactory.newLatLng(point);
            map.moveCamera(c);
        }
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
        map.animateCamera(zoom);
        map.getUiSettings().setZoomControlsEnabled(false);
    }
}
Also used : CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 18 with CameraUpdate

use of com.google.android.gms.maps.CameraUpdate in project Ushahidi_Android by ushahidi.

the class MapUserLocation method updateMarker.

protected void updateMarker(LatLng point, boolean center) {
    if (map != null) {
        if (updatableMarker == null) {
            CameraUpdate p = CameraUpdateFactory.newLatLng(point);
            map.moveCamera(p);
            updatableMarker = createUpdatableMarker(point);
        } else {
            updatableMarker.update(point);
        }
        if (center) {
            CameraUpdate c = CameraUpdateFactory.newLatLng(point);
            map.moveCamera(c);
        }
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(ZOOM);
        map.animateCamera(zoom);
        map.getUiSettings().setZoomControlsEnabled(false);
    }
}
Also used : CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 19 with CameraUpdate

use of com.google.android.gms.maps.CameraUpdate in project YourAppIdea by Michenux.

the class SimpleMapFragment method onLocationChanged.

@Override
public void onLocationChanged(Location location) {
    if (BuildConfig.DEBUG) {
        Log.d(YourApplication.LOG_TAG, "simpleMapFragment.onLocationChanged");
    }
    if (mMap != null) {
        LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(loc, 15);
        mMap.animateCamera(cameraUpdate);
    }
}
Also used : LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 20 with CameraUpdate

use of com.google.android.gms.maps.CameraUpdate in project IITB-App by wncc.

the class MapFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    locationButton = (FloatingActionButton) getActivity().findViewById(R.id.location_button);
    locationButton.setImageResource(R.drawable.ic_my_location_black_24dp);
    locationButton.getDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimaryDark), PorterDuff.Mode.SRC_IN);
    locationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.v("MapFragment", "Location button pressed");
            try {
                LocationManager lm = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
                boolean gps_enabled = false;
                boolean network_enabled = false;
                if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSIONS_REQUEST_LOCATION);
                    return;
                }
                try {
                    gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
                } catch (Exception ex) {
                }
                try {
                    network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                } catch (Exception ex) {
                }
                if (!gps_enabled && !network_enabled) {
                    LocationRequest locationRequest = LocationRequest.create();
                    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
                    locationRequest.setInterval(30 * 1000);
                    locationRequest.setFastestInterval(5 * 1000);
                    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
                    // **************************
                    // this is the key ingredient
                    builder.setAlwaysShow(true);
                    // **************************
                    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
                    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {

                        @Override
                        public void onResult(LocationSettingsResult result) {
                            final Status status = result.getStatus();
                            final LocationSettingsStates state = result.getLocationSettingsStates();
                            switch(status.getStatusCode()) {
                                case LocationSettingsStatusCodes.SUCCESS:
                                    // requests here.
                                    break;
                                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                                    // a dialog.
                                    try {
                                        // Show the dialog by calling startResolutionForResult(),
                                        // and check the result in onActivityResult().
                                        status.startResolutionForResult(getActivity(), 1000);
                                    } catch (IntentSender.SendIntentException e) {
                                    // Ignore the error.
                                    }
                                    break;
                                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                                    // settings so we won't show the dialog.
                                    break;
                            }
                        }
                    });
                }
                currentLocation = getLastKnownLocation();
                if (currentLocation != null) {
                    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 17);
                    googleMap.animateCamera(cameraUpdate);
                    locationButton.getDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
                }
            } catch (Exception e) {
                checkLocationPermission();
                Toast.makeText(getContext(), "Please turn on Location from the Settings", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Status(com.google.android.gms.common.api.Status) ResultCallback(com.google.android.gms.common.api.ResultCallback) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) LocationSettingsStates(com.google.android.gms.location.LocationSettingsStates) View(android.view.View) PendingResult(com.google.android.gms.common.api.PendingResult) LatLng(com.google.android.gms.maps.model.LatLng) IntentSender(android.content.IntentSender) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Aggregations

CameraUpdate (com.google.android.gms.maps.CameraUpdate)20 LatLng (com.google.android.gms.maps.model.LatLng)18 View (android.view.View)2 Intent (android.content.Intent)1 IntentSender (android.content.IntentSender)1 LocationManager (android.location.LocationManager)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 PendingResult (com.google.android.gms.common.api.PendingResult)1 ResultCallback (com.google.android.gms.common.api.ResultCallback)1 Status (com.google.android.gms.common.api.Status)1 LocationRequest (com.google.android.gms.location.LocationRequest)1 LocationSettingsResult (com.google.android.gms.location.LocationSettingsResult)1 LocationSettingsStates (com.google.android.gms.location.LocationSettingsStates)1 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 ListReportCommentActivity (com.ushahidi.android.app.ui.phone.ListReportCommentActivity)1 ViewReportNewsActivity (com.ushahidi.android.app.ui.phone.ViewReportNewsActivity)1 ViewReportPhotoActivity (com.ushahidi.android.app.ui.phone.ViewReportPhotoActivity)1