0

I would like to zoom and position my GoogleMap such that all markers, including the blue MyLocation marker, are visible. This SO question shows how to do this for all manually added markers, but I am not sure how to get a handle to the MyLocation marker, which is automatically added after calling setMyLocationEnabled(true), in order to pass it to the LatLngBounds.Builder.

I have tried using GoogleMap.getMyLocation(), and I am calling it in onPostCreate, after the map has been fully initialized. The call returns null though. This SO answer talks about a bug with getMyLocation(), but also mentions that it was fixed.

Community
  • 1
  • 1
theblang
  • 10,215
  • 9
  • 69
  • 120

1 Answers1

0

To add to that LatLng of my location blue dot, use GoogleMap.getMyLocation() or if you want to update camera every time that location changes, GoogleMap.setOnMyLocationChangeListener(...) and then convert Location to LatLng.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • I am calling `getMyLocation()` in `onPostCreate`, but I just get `null`. [This SO answer](http://stackoverflow.com/a/13830598/1747491) talks about a bug with the function, but also says that it was supposedly fixed. – theblang Nov 21 '13 at 15:15
  • @mattblang `onPostCreate` is too early to call `getMyLocation`. Use listener or call it in when some button is clicked. – MaciejGórski Nov 21 '13 at 15:59
  • I tried it in `onResume` as well to see if it would work, but still `null`. The problem with `onLocationChanged` is that the listener won't fire on initialization. I noticed that `getMyLocation` is deprecated, so I switched to the methods they use in the demo file that is referenced in the `getMyLocation` documentation. Using the SO question that I linked, I was able to get it working. The one remaining problem is that the padding doesn't do anything, so markers are on the very edge. – theblang Nov 21 '13 at 17:03