Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Android Camera API #3244

Closed
Closed

Description

@bleege

The next iteration of the map interaction API should be to add a Camera API. The Camera API will be modeled on the Google Maps Android API to maximize familiarity. Key classes will be:

/cc @zugaldia @incanus @twbell

Activity

  1. added
    Android
    on Dec 10, 2015
  2. added this to the milestone on Dec 10, 2015
  3. bleege commented on Dec 10, 2015

    @bleege
    ContributorAuthor

    Related to #2805

  4. added a commit that references this issue on Dec 10, 2015
  5. added 4 commits that reference this issue on Dec 10, 2015
  6. bleege commented on Dec 10, 2015

    @bleege
    ContributorAuthor

    Basic classes, method stubs, and a TestApp activity are built. The next step is wiring up Core GL to the method stubs and verifying via TestApp activity.

  7. added 2 commits that reference this issue on Dec 11, 2015
  8. 60 remaining items

  9. bleege commented on Dec 18, 2015

    @bleege
    ContributorAuthor

    Per chat, @zugaldia kicked the tires this morning on the branch and is happy with things. The only tweaks that we'll make are adding @UIThread annotations to the animateCamera() methods to remind everyone that these should only be used on the UI Thread as per regular Android UI conventions. As part of this we can also remove the View.post(new Runnable(){}) forced UI Thread wrapping of Callback firing command since everything will be on the UIThread.

    Once these tweaks are made and tested that'll wrap up Iteration 0 on the Camera API and will then merge into master.

    /cc @twbell

  10. added a commit that references this issue on Dec 18, 2015
  11. bleege commented on Dec 18, 2015

    @bleege
    ContributorAuthor

    Thanks to @jfirebaugh's help with git rebasing the Camera API is now merged into master for everyone to enjoy!

  12. added a commit that references this issue on Dec 18, 2015
  13. mb12 commented on Dec 18, 2015

    @mb12

    @bleege Is two finger drag gesture to tilt also available?

  14. bleege commented on Dec 18, 2015

    @bleege
    ContributorAuthor

    Is two finger drag gesture to tilt also available?

    @mb12 Yep. That's been in there since 2.3.0.

  15. KidusMT commented on May 11, 2018

    @KidusMT

    My Camera Animation is not working on API 23 and higher...but works fine on lower...Have this issue been solved? Please help!
    here is my code...

    // Marker
            mapboxMap.addMarker(new MarkerOptions()
                    .position(new LatLng(latitude, longitude))
                    .icon(icon));
    
            //41.900581, 12.487007 - Italy Rome
            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(latitude, longitude)) // Sets the new camera position
                    .zoom(17) // Sets the zoom
                    .bearing(180) // Rotate the camera
                    .tilt(30) // Set the camera tilt
                    .build(); // Creates a CameraPosition from the builder
    
            mapboxMap.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition), 7000);
    
    

    here is how it's been called in the onMapReady() method

    @Override
        public void onMapReady(MapboxMap mapboxMap) {
            map = mapboxMap;
    
            mapboxMap.setOnMarkerClickListener(this);
    
            //Controlling the components on the mapBox
            mapboxMap.getUiSettings().setZoomControlsEnabled(false);//hide zoom control button
            mapboxMap.getUiSettings().setCompassEnabled(false);//hide compass
            mapboxMap.getUiSettings().setZoomGesturesEnabled(true);
            mapboxMap.getUiSettings().setScrollGesturesEnabled(true);
            mapboxMap.getUiSettings().setAllGesturesEnabled(true);
    
            // Create an Icon object for the marker to use
            Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.marker);
    
            //This is the part where we check for the whether the permissions that are needed for this
            //feature is allowed or not.
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
                    this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
    
            //Animate the camera and locate the marker
            updateMap(41.900581, 12.487007, mapboxMap, icon);
        }
    
  16. LukasPaczos commented on May 11, 2018

    @LukasPaczos
    Contributor

    @KidusMT What SDK version are you using? Could you check if there are no exceptions printed in your Logcat after the map is loaded?

  17. KidusMT commented on May 12, 2018

    @KidusMT

    @LukasPaczos For some reason which I am not sure why but it worked like this now

     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Mapbox access token is configured here. This needs to be called either in your application
    
            // object or in the same activity which contains the mapview.
            Mapbox.getInstance(this, BuildConfig.MAPBOX_API_KEY);
    
            // This contains the MapView in XML and needs to be called after the access token is configured.
            setContentView(R.layout.activity_map);
    
            mapView = findViewById(R.id.mapView);
    
            mapView.onCreate(savedInstanceState);
            mapView.getMapAsync(mapboxMap -> {
    
                //Controlling the components on the mapBox
                mapboxMap.getUiSettings().setZoomControlsEnabled(false);//hide zoom control button
                mapboxMap.getUiSettings().setCompassEnabled(false);//hide compass
                mapboxMap.getUiSettings().setZoomGesturesEnabled(true);
                mapboxMap.getUiSettings().setScrollGesturesEnabled(true);
                mapboxMap.getUiSettings().setAllGesturesEnabled(true);
    
                mapboxMap.setOnMarkerClickListener(this);
    
                // Create an Icon object for the marker to use
                Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.marker);
    
                updateMap(41.900581, 12.487007, mapboxMap, icon);
    
                //Don't forget the setCoordinate chain method is reverse while taking arguments NOTE that!
    
                MapboxGeocoder client = new MapboxGeocoder.Builder()
                        .setAccessToken(BuildConfig.MAPBOX_API_KEY)
                        .setCoordinates(12.487007, 41.900581)
                        .setType(GeocoderCriteria.TYPE_POI)
                        .build();
    
                client.enqueue(new Callback<GeocoderResponse>() {
    
                    @Override
                    public void onResponse(Response<GeocoderResponse> response, Retrofit retrofit) {
                        if (response.isSuccess()) {
                            if (response.body().getFeatures().size() > 0) {
                                placeName = response.body().getFeatures().get(0).getText();
                                String tempLocation = response.body().getFeatures().get(0).getPlaceName();
                                if (tempLocation.contains(",")) {
                                    String[] places = TextUtils.split(response.body().getFeatures().get(0).getPlaceName(), ",");
                                    if (places.length > 1) {
                                        address = places[1];
                                    }
                                }
                            }
    
                        } else {
                            //TODO add something later
                        }
                    }
    
                    @Override
                    public void onFailure(Throwable t) {
                    }
                });
    
    
                //TODO IMPROVE THE INFO WINDOW
    
                mapboxMap.setInfoWindowAdapter(marker1 -> {
    
                    View v = getLayoutInflater().inflate(R.layout.layout_callout, null);
                    TextView title = v.findViewById(R.id.title);
                    TextView logo = v.findViewById(R.id.logoView);
                    TextView subTitle = v.findViewById(R.id.sub_title);
                    if (!placeName.isEmpty()) {
                        title.setText(placeName);
                        logo.setText(placeName.substring(0, 1));
                    }
    
                    subTitle.setText(address);
                    return v;
    
                });
    
                mapboxMap.setOnInfoWindowClickListener(marker -> {
                    startActivity(new Intent(MapActivity.this, DetailActivity.class));
                    return true;
                });
    
            });
    
         
        }
    
        private void updateMap(double latitude, double longitude, MapboxMap mapboxMap, Icon icon) {
    
            // Marker
            mapboxMap.addMarker(new MarkerOptions()
                    .position(new LatLng(latitude, longitude))
                    .icon(icon));
    
    
            //41.900581, 12.487007 - Italy Rome
            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(latitude, longitude)) // Sets the new camera position
                    .zoom(17) // Sets the zoom
                    .bearing(180) // Rotate the camera
                    .tilt(30) // Set the camera tilt
                    .build(); // Creates a CameraPosition from the builder
    
            mapboxMap.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition), 7000);
    
        }
    

    this is my SDK version defined in the build config

    ext.configuration = [   
            compileSdkVersion: 27,
            targetSdkVersion : 27,
            buildToolsVersion: "27.0.3"
    ]
    

    now its working on all API level I am targeting to work the app for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Android

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions