1

I want to know if is it possible to be aware when GoogleMaps provides/displays the blue dot which represents the current location of the user.
In fact, i'd like to display a progress bar until that blue dot is provided, that's why I have to know when the latter is available.
I'm currently using the LocationClient class to get user's location after calling the connect() method but I actually can't determine when it gets a good location fix (represented by the blue dot).
I also want to zoom in the location found when it is available, that's why i'm using this callback function which sometimes zoom in a wrong location if a fix hasn't be found yet.

private LocationResult locDepart = new LocationResult() {       
    @Override
    public void gotLocation(Location location) {    
        Location loc = location;
        if (loc != null) {
            LatLng coordonnees = new LatLng(loc.getLatitude(), loc.getLongitude());
            final CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(coordonnees)      // Sets the center of the map to Mountain View
            .zoom(18)                   // Sets the zoom
            .bearing(90)                // Sets the orientation of the camera to east
            .tilt(10)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
            runOnUiThread(new Runnable () {
                @Override
                public void run() {
                    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
                }           
            });
        } 
        mHandler.sendEmptyMessage(0);
    }
};

Thanks for your answers.

Sw4Tish
  • 202
  • 4
  • 12

2 Answers2

0

You can replace built-in my location feature with own marker, so showing progress bar (or busy) unless location fix is provided by location provider should be trivial

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • In fact, the blue dot is efficient so if I could keep him not using my own marker, I'll do it. My app is for short distance so I have to be the most accurate possible. – Sw4Tish Aug 21 '13 at 11:10
  • Dot cannot be efficient. It's just image. So you can easily be as efficient as the dot by listening to location provider yourself – Marcin Orlowski Aug 21 '13 at 14:04
0

Use

googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
    ...
});

to make yourself aware of when blue dot's position changes.

If you set it before enabling myLocation dot, you should be called back when it first appears.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • Thanks for your answer, I've already checked it and the interface is deprecated so I'm using LocationClient instead – Sw4Tish Aug 22 '13 at 08:37
  • @Sw4Tish The deprecation is incorrect IMHO. Treat `setOnMyLocationChangeListener` as a convenience method for what you can achieve using `LocationClient` with a lot of unnecessary code. See a discussion I made with myself [in this question](http://stackoverflow.com/questions/16971309/google-maps-android-api-v2-apis-related-to-my-location-deprecated-why). – MaciejGórski Aug 22 '13 at 08:40
  • I've read it and I must admit I agree with you because as you said it's a convenience method. Since I think I can't achieve what I desire I might use this instead. Give you accepted answer. – Sw4Tish Aug 22 '13 at 08:48