0

I tried this solution Show Current Location inside Google Map Fragment answered by Daniel Nugent.

But here is bug. First when you locate Pin and (blue Dot) stay on same position, but when you change your location only blue dot change location Pin stayed on old position.

Only one time enter in override method by GoogleAPI

@Override
public void onLocationChanged(Location location){}

Pin and blue dot

Community
  • 1
  • 1
storks
  • 419
  • 2
  • 8
  • 15

1 Answers1

0

I updated the original answer since that one section was causing too much confusion.

In order to keep location updates going after the first one is received, remove the call to removeLocationUpdates() in the onLocationChanged() override:

@Override
public void onLocationChanged(Location location)
{
    mLastLocation = location;
    if (mCurrLocationMarker != null) {
        mCurrLocationMarker.remove();
    }

    //Place current location marker
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);

    //move map camera
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));

}
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137