mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
maps intent: preserve zoom and show red pin (#6160)
Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
41170d81d9
commit
e01ecb20fa
5 changed files with 36 additions and 13 deletions
|
|
@ -148,13 +148,27 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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(Context context, LatLng latLng) {
|
||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri());
|
||||
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(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 {
|
||||
|
|
|
|||
|
|
@ -545,8 +545,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
|||
* @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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2309,7 +2309,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue