2
2
3
3
import android .content .Context ;
4
4
import android .content .pm .PackageManager ;
5
- import android .location .Criteria ;
6
- import android .location .Location ;
7
- import android .location .LocationManager ;
8
5
import android .os .Bundle ;
9
6
import android .support .v4 .app .ActivityCompat ;
10
7
import android .support .v7 .app .ActionBarActivity ;
11
8
import android .util .Log ;
12
9
import android .widget .Toast ;
13
10
11
+ import com .google .android .gms .maps .CameraUpdate ;
14
12
import com .google .android .gms .maps .CameraUpdateFactory ;
15
13
import com .google .android .gms .maps .GoogleMap ;
16
14
import com .google .android .gms .maps .OnMapReadyCallback ;
17
15
import com .google .android .gms .maps .SupportMapFragment ;
18
16
import com .google .android .gms .maps .model .BitmapDescriptorFactory ;
17
+ import com .google .android .gms .maps .model .CameraPosition ;
19
18
import com .google .android .gms .maps .model .LatLng ;
20
19
import com .google .android .gms .maps .model .Marker ;
21
20
import com .google .android .gms .maps .model .MarkerOptions ;
@@ -29,6 +28,8 @@ public class PrivyMapsActivity extends ActionBarActivity implements OnMapReadyCa
29
28
private GoogleMap mMap ;
30
29
private Context mContext ;
31
30
private Marker myLocationMarker ;
31
+ private CameraPosition MY_LOCATION_CAMERA_POS ;
32
+ private static final int CAMERA_ANIMATION_DURATION = 2500 ;
32
33
33
34
// My Location
34
35
private LocationData myLocationData ;
@@ -99,15 +100,42 @@ public boolean onMyLocationButtonClick() {
99
100
myLocationMarker .remove ();
100
101
}
101
102
103
+ MY_LOCATION_CAMERA_POS = new CameraPosition .Builder ()
104
+ .target (myLocationData .getLatLng ())
105
+ .zoom (15.0f )
106
+ .bearing (0 )
107
+ .tilt (25 )
108
+ .build ();
109
+
102
110
myLocationMarker = mMap .addMarker (new MarkerOptions ().position (myLocationData .getLatLng ()).title ("My Location" ));
103
- mMap .moveCamera (CameraUpdateFactory .newLatLngZoom (myLocationData .getLatLng (), 15.0f ));
111
+
112
+ //animate camera
113
+ onGoToMyLocation ();
104
114
Log .d (DEBUG , myLocationData .getLatLng ().toString ());
105
115
}
106
116
return true ;
107
117
}
108
118
});
109
119
}
110
120
121
+ private void onGoToMyLocation () {
122
+ changeCamera (CameraUpdateFactory .newCameraPosition (MY_LOCATION_CAMERA_POS ), new GoogleMap .CancelableCallback () {
123
+ @ Override
124
+ public void onFinish () {
125
+ Toast .makeText (mContext ,"Animation Finished" ,Toast .LENGTH_SHORT ).show ();
126
+ }
127
+
128
+ @ Override
129
+ public void onCancel () {
130
+ Toast .makeText (mContext ,"Animation Canceled" ,Toast .LENGTH_SHORT ).show ();
131
+ }
132
+ });
133
+ }
134
+
135
+ private void changeCamera (CameraUpdate update , GoogleMap .CancelableCallback callback ){
136
+ mMap .animateCamera (update ,CAMERA_ANIMATION_DURATION ,callback );
137
+ }
138
+
111
139
private boolean checkLocationEnabledPermission () {
112
140
if (ActivityCompat .checkSelfPermission (this , android .Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED && ActivityCompat .checkSelfPermission (this , android .Manifest .permission .ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
113
141
// TODO: Consider calling
0 commit comments