Skip to content

Commit 9f18df3

Browse files
committed
maps intent: preserve zoom and show red pin
1 parent 77bad33 commit 9f18df3

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

app/src/main/java/fr/free/nrw/commons/Utils.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,27 @@ public static void handleWebUrl(Context context, Uri url) {
148148
}
149149

150150
/**
151-
* Util function to handle geo coordinates
152-
* It no longer depends on google maps and any app capable of handling the map intent can handle it
153-
* @param context
154-
* @param latLng
151+
* Util function to handle geo coordinates. It no longer depends on google maps and any app
152+
* capable of handling the map intent can handle it
153+
*
154+
* @param context The context for launching intent
155+
* @param latLng The latitude and longitude of the location
156+
*/
157+
public static void handleGeoCoordinates(final Context context, final LatLng latLng) {
158+
handleGeoCoordinates(context, latLng, 16);
159+
}
160+
161+
/**
162+
* Util function to handle geo coordinates with specified zoom level. It no longer depends on
163+
* google maps and any app capable of handling the map intent can handle it
164+
*
165+
* @param context The context for launching intent
166+
* @param latLng The latitude and longitude of the location
167+
* @param zoomLevel The zoom level
155168
*/
156-
public static void handleGeoCoordinates(Context context, LatLng latLng) {
157-
Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri());
169+
public static void handleGeoCoordinates(final Context context, final LatLng latLng,
170+
final double zoomLevel) {
171+
final Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri(zoomLevel));
158172
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
159173
context.startActivity(mapIntent);
160174
} else {

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,9 @@ public void hideBottomDetailsSheet() {
545545
* @param place Place of clicked nearby marker
546546
*/
547547
private void passInfoToSheet(final Place place) {
548-
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
549-
place.getLocation()));
548+
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(
549+
view -> Utils.handleGeoCoordinates(getActivity(),
550+
place.getLocation(), binding.mapView.getZoomLevelDouble()));
550551

551552
binding.bottomSheetDetailsBinding.commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
552553
binding.bottomSheetDetailsBinding.commonsButton.setOnClickListener(

app/src/main/java/fr/free/nrw/commons/location/LatLng.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ data class LatLng(
123123

124124
/**
125125
* Gets a URI for a Google Maps intent at the location.
126+
*
127+
* @paraam zoom The zoom level
128+
* @return URI for the intent
126129
*/
127-
fun getGmmIntentUri(): Uri {
128-
return Uri.parse("geo:$latitude,$longitude?z=16")
129-
}
130+
fun getGmmIntentUri(zoom: Double): Uri = Uri.parse(
131+
"geo:$latitude,$longitude?q=$latitude,$longitude&z=${zoom}"
132+
)
130133

131134
override fun writeToParcel(parcel: Parcel, flags: Int) {
132135
parcel.writeDouble(latitude)

app/src/main/java/fr/free/nrw/commons/locationpicker/LocationPickerActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ class LocationPickerActivity : BaseActivity(), LocationPermissionCallback {
430430
else -> null
431431
}
432432

433-
position?.let { Utils.handleGeoCoordinates(this, it) }
433+
position?.let {
434+
mapView?.zoomLevelDouble?.let { zoomLevel ->
435+
Utils.handleGeoCoordinates(this, it, zoomLevel)
436+
} ?: Utils.handleGeoCoordinates(this, it)
437+
}
434438
}
435439

436440
/**

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,8 @@ public void onBottomSheetItemClick(@Nullable View view, int position) {
23092309
updateBookmarkButtonImage(selectedPlace);
23102310
break;
23112311
case R.drawable.ic_directions_black_24dp:
2312-
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
2312+
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation(),
2313+
binding.map.getZoomLevelDouble());
23132314
break;
23142315
case R.drawable.ic_wikidata_logo_24dp:
23152316
Utils.handleWebUrl(this.getContext(), selectedPlace.siteLinks.getWikidataLink());

0 commit comments

Comments
 (0)