Devrath
Devrath

Reputation: 42824

Location button not enabled in android google maps

What i have:

I have a running google maps

What is happening:

I cannot see the location button on the map

What i want

enter image description here

Code:

i have called this function in oncreate, i have instance of google map

private void initilizeMap() {
        try {
            if (googleMap == null) {
                //Map Explicit settings//
                //Map Rotate Gesture
                googleMap.getUiSettings().setRotateGesturesEnabled(true);
                //My Location Button
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                //Compass Functionality
                googleMap.getUiSettings().setCompassEnabled(true);
                //Zooming Functionality
                googleMap.getUiSettings().setZoomGesturesEnabled(true);
                //Zooming Buttons
                googleMap.getUiSettings().setZoomControlsEnabled(true);
                //Showing Current Location
                googleMap.setMyLocationEnabled(true);


                // check if map is created successfully or not
                if (googleMap == null) {
                    Toast.makeText(this,"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
                }
            }
        } catch (Exception e) {


        }
    }

manifest

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Note :: I can see zoom controlls but not location

Upvotes: 1

Views: 674

Answers (1)

Vishal Dasadiya
Vishal Dasadiya

Reputation: 2585

GoogleMaps instance you created with your map.

// map is a GoogleMap object


map.setMyLocationEnabled(true);

and

 // Get the button view 

View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);

// and next place it, for exemple, on bottom right (as Google Maps app)

RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
// position on right bottom

rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
rlp.setMargins(0, 0, 30, 30);

Upvotes: 1

Related Questions