Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My-Location Button of GoogleMaps v2 Android, not displayed

I'm doing an app, with google maps, but when I try to add "my-location" button, as the reference says doesn't work...

thats how I do:

protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();          locManager = (LocationManager)getSystemService(LOCATION_SERVICE);         providersList = locManager.getAllProviders();         provider =locManager.getProvider(providersList.get(0));         precision = provider.getAccuracy();         req = new Criteria();         req.setAccuracy(Criteria.ACCURACY_FINE);                 inside = false;          map.getUiSettings().setMyLocationButtonEnabled(true);          buildPolygon();         drawPolygon();         startLocalization();     } 

I used map.getUiSettings().setMyLocationButtonEnabled(true); as shows in the reference of google. I don't know what's going on..

like image 939
Shudy Avatar asked Apr 22 '13 14:04

Shudy


People also ask

How do I turn on current location on Android?

There are two ways to get the current location of any Android device: Android's Location Manager API. Fused Location Provider: Google Play Services Location APIs.

How do I turn on my location on Google Maps Android?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


2 Answers

The myLocationButtonEnabled is true by default and shown when the setMyLocationEnabled layer is enabled.

try this:

protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();      // Add this line     map.setMyLocationEnabled(true);      locManager = (LocationManager)getSystemService(LOCATION_SERVICE);     providersList = locManager.getAllProviders();     provider =locManager.getProvider(providersList.get(0));     precision = provider.getAccuracy();     req = new Criteria();     req.setAccuracy(Criteria.ACCURACY_FINE);             inside = false;      //map.getUiSettings().setMyLocationButtonEnabled(true);      buildPolygon();     drawPolygon();     startLocalization(); } 

setMyLocationEnabled Documentation
setMyLocationButtonEnabled Documentation

like image 67
jnthnjns Avatar answered Oct 08 '22 22:10

jnthnjns


just add map.setMyLocationEnabled(true); after create your map

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 

to be like this

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();  map.setMyLocationEnabled(true); 
like image 28
Mina Fawzy Avatar answered Oct 08 '22 22:10

Mina Fawzy