Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set your camera to a particular location in yor google map in android app?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 382
    Comment on it

    If you wish to show a particular location on google map in your android app, this can be done by using the following code in the activity where you have implemented the map :-

    public class LTJMapActivity extends FragmentActivity implements OnMapReadyCallback {
    
        private GoogleMap mMap;
        private static String name,callid,callerid,calleeid;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ltjmap);
            // Obtain the SupportMapFragment and get notified when the map is ready to be used.
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
    
           
        }
    
    
        /**
         * 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;
            Marker mMarker;
            // Add a marker in Sydney and move the camera
    
            LatLng sydney = new LatLng(40.74319429984035,-73.98653626441956);
            final CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(sydney)      // Sets the center of the map to Mountain View
                    .zoom(17)                   // Sets the zoom
                    .bearing(30)                // Sets the orientation of the camera to east
                    .tilt(50)                   // Sets the tilt of the camera to 30 degrees
                    .build();
            mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
            mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }
    }

    The main work is being performed in the overridden method onMapReady where the latitude and longitude are being set for the location that you wish to show in your map, below is the code.

     LatLng sydney = new LatLng(40.74319429984035,-73.98653626441956);

    To set the zoom level use ".zoom()", and for tilt use ".tilt()" as done in the code above.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: