Skip to content

Commit

Permalink
maps intent: preserve zoom and show red pin
Browse files Browse the repository at this point in the history
  • Loading branch information
savsch committed Jan 27, 2025
1 parent 77bad33 commit b93cda1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
26 changes: 20 additions & 6 deletions app/src/main/java/fr/free/nrw/commons/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,27 @@ public static void handleWebUrl(Context context, Uri url) {
}

/**
* Util function to handle geo coordinates
* It no longer depends on google maps and any app capable of handling the map intent can handle it
* @param context
* @param latLng
* Util function to handle geo coordinates. It no longer depends on google maps and any app
* capable of handling the map intent can handle it
*
* @param context The context for launching intent
* @param latLng The latitude and longitude of the location
*/
public static void handleGeoCoordinates(final Context context, final LatLng latLng) {
handleGeoCoordinates(context, latLng, 16);
}

/**
* Util function to handle geo coordinates with specified zoom level. It no longer depends on
* google maps and any app capable of handling the map intent can handle it
*
* @param context The context for launching intent
* @param latLng The latitude and longitude of the location
* @param zoomLevel The zoom level
*/
public static void handleGeoCoordinates(Context context, LatLng latLng) {
Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri());
public static void handleGeoCoordinates(final Context context, final LatLng latLng,
final double zoomLevel) {
final Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri(zoomLevel));
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(mapIntent);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ public void hideBottomDetailsSheet() {
* @param place Place of clicked nearby marker
*/
private void passInfoToSheet(final Place place) {
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
place.getLocation()));
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(
view -> Utils.handleGeoCoordinates(getActivity(),
place.getLocation(), binding.mapView.getZoomLevelDouble()));

binding.bottomSheetDetailsBinding.commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
binding.bottomSheetDetailsBinding.commonsButton.setOnClickListener(
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/fr/free/nrw/commons/location/LatLng.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@ data class LatLng(

/**
* Gets a URI for a Google Maps intent at the location.
*
* @paraam zoom The zoom level
* @return URI for the intent
*/
fun getGmmIntentUri(): Uri {
return Uri.parse("geo:$latitude,$longitude?z=16")
}
fun getGmmIntentUri(zoom: Double): Uri = Uri.parse(
"geo:$latitude,$longitude?q = $latitude, $longitude&z=${zoom}"
)

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,11 @@ class LocationPickerActivity : BaseActivity(), LocationPermissionCallback {
else -> null
}

position?.let { Utils.handleGeoCoordinates(this, it) }
position?.let {
mapView?.zoomLevelDouble?.let { zoomLevel ->
Utils.handleGeoCoordinates(this, it, zoomLevel)
} ?: Utils.handleGeoCoordinates(this, it)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,8 @@ public void onBottomSheetItemClick(@Nullable View view, int position) {
updateBookmarkButtonImage(selectedPlace);
break;
case R.drawable.ic_directions_black_24dp:
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation(),
binding.map.getZoomLevelDouble());
break;
case R.drawable.ic_wikidata_logo_24dp:
Utils.handleWebUrl(this.getContext(), selectedPlace.siteLinks.getWikidataLink());
Expand Down

0 comments on commit b93cda1

Please sign in to comment.