11
11
12
12
import android .content .Intent ;
13
13
import android .graphics .BitmapFactory ;
14
+ import android .location .Location ;
14
15
import android .os .Bundle ;
15
16
import android .text .Html ;
16
17
import android .text .method .LinkMovementMethod ;
20
21
import android .widget .Button ;
21
22
import android .widget .ImageView ;
22
23
import android .widget .TextView ;
24
+ import android .widget .Toast ;
23
25
import androidx .annotation .NonNull ;
24
26
import androidx .annotation .Nullable ;
25
27
import androidx .appcompat .app .ActionBar ;
29
31
import androidx .lifecycle .Observer ;
30
32
import androidx .lifecycle .ViewModelProvider ;
31
33
import com .google .android .material .floatingactionbutton .FloatingActionButton ;
34
+ import com .mapbox .android .core .location .LocationEngineCallback ;
35
+ import com .mapbox .android .core .location .LocationEngineResult ;
32
36
import com .mapbox .android .core .permissions .PermissionsManager ;
33
37
import com .mapbox .geojson .Point ;
34
38
import com .mapbox .mapboxsdk .camera .CameraPosition ;
@@ -92,6 +96,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
92
96
* activity : activity key
93
97
*/
94
98
private String activity ;
99
+ /**
100
+ * location : location
101
+ */
102
+ private Location location ;
95
103
/**
96
104
* modifyLocationButton : button for start editing location
97
105
*/
@@ -104,6 +112,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
104
112
* placeSelectedButton : fab for selecting location
105
113
*/
106
114
FloatingActionButton placeSelectedButton ;
115
+ /**
116
+ * fabCenterOnLocation: button for center on location;
117
+ */
118
+ FloatingActionButton fabCenterOnLocation ;
107
119
/**
108
120
* droppedMarkerLayer : Layer for static screen
109
121
*/
@@ -154,6 +166,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
154
166
addPlaceSelectedButton ();
155
167
addCredits ();
156
168
getToolbarUI ();
169
+ addCenterOnGPSButton ();
157
170
158
171
if ("UploadActivity" .equals (activity )) {
159
172
placeSelectedButton .setVisibility (View .GONE );
@@ -162,6 +175,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
162
175
largeToolbarText .setText (getResources ().getString (R .string .image_location ));
163
176
smallToolbarText .setText (getResources ().
164
177
getString (R .string .check_whether_location_is_correct ));
178
+ fabCenterOnLocation .setVisibility (View .GONE );
165
179
}
166
180
167
181
mapView .onCreate (savedInstanceState );
@@ -275,6 +289,7 @@ private void onClickModifyLocation() {
275
289
largeToolbarText .setText (getResources ().getString (R .string .choose_a_location ));
276
290
smallToolbarText .setText (getResources ().getString (R .string .pan_and_zoom_to_adjust ));
277
291
bindListeners ();
292
+ fabCenterOnLocation .setVisibility (View .VISIBLE );
278
293
}
279
294
280
295
/**
@@ -339,6 +354,20 @@ private void enableLocationComponent(@NonNull final Style loadedMapStyle) {
339
354
// Set the component's render mode
340
355
locationComponent .setRenderMode (RenderMode .NORMAL );
341
356
357
+ // Get the component's location engine to receive user's last location
358
+ locationComponent .getLocationEngine ().getLastLocation (
359
+ new LocationEngineCallback <LocationEngineResult >() {
360
+ @ Override
361
+ public void onSuccess (LocationEngineResult result ) {
362
+ location = result .getLastLocation ();
363
+ }
364
+
365
+ @ Override
366
+ public void onFailure (@ NonNull Exception exception ) {
367
+ }
368
+ });
369
+
370
+
342
371
}
343
372
}
344
373
@@ -405,6 +434,19 @@ void placeSelected() {
405
434
setResult (AppCompatActivity .RESULT_OK , returningIntent );
406
435
finish ();
407
436
}
437
+ /**
438
+ * Center the camera on the last saved location
439
+ */
440
+ private void addCenterOnGPSButton (){
441
+ fabCenterOnLocation = findViewById (R .id .center_on_gps );
442
+ fabCenterOnLocation .setOnClickListener (view -> getCenter ());
443
+ }
444
+ /**
445
+ * Animate map to move to desired Latitude and Longitude
446
+ */
447
+ void getCenter () {
448
+ mapboxMap .animateCamera (CameraUpdateFactory .newLatLngZoom (new LatLng (location .getLatitude (),location .getLongitude ()),15.0 ));
449
+ }
408
450
409
451
@ Override
410
452
protected void onStart () {
0 commit comments