Skip to content

Commit 1530722

Browse files
authored
Merge pull request #20 from espertus/display-location-fix
Update camera position on location change
2 parents e27d2a0 + 2386dda commit 1530722

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/src/main/java/com/example/mapdemo/MapDemoActivity.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,12 @@ private boolean isGooglePlayServicesAvailable() {
171171
protected void onResume() {
172172
super.onResume();
173173

174-
// Display the connection status
174+
displayLocation();
175175

176+
MapDemoActivityPermissionsDispatcher.startLocationUpdatesWithPermissionCheck(this);
177+
}
178+
179+
private void displayLocation() {
176180
if (mCurrentLocation != null) {
177181
Toast.makeText(this, "GPS location was found!", Toast.LENGTH_SHORT).show();
178182
LatLng latLng = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
@@ -181,7 +185,6 @@ protected void onResume() {
181185
} else {
182186
Toast.makeText(this, "Current location was null, enable GPS on emulator!", Toast.LENGTH_SHORT).show();
183187
}
184-
MapDemoActivityPermissionsDispatcher.startLocationUpdatesWithPermissionCheck(this);
185188
}
186189

187190
@NeedsPermission({Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})
@@ -213,13 +216,12 @@ public void onLocationChanged(Location location) {
213216
return;
214217
}
215218

216-
// Report to the UI that the location was updated
217-
218219
mCurrentLocation = location;
219220
String msg = "Updated Location: " +
220221
Double.toString(location.getLatitude()) + "," +
221222
Double.toString(location.getLongitude());
222223
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
224+
displayLocation();
223225
}
224226

225227
public void onSaveInstanceState(Bundle savedInstanceState) {

0 commit comments

Comments
 (0)