mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +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
|
* Util function to handle geo coordinates. It no longer depends on google maps and any app
|
||||||
* It no longer depends on google maps and any app capable of handling the map intent can handle it
|
* capable of handling the map intent can handle it
|
||||||
* @param context
|
*
|
||||||
* @param latLng
|
* @param context The context for launching intent
|
||||||
|
* @param latLng The latitude and longitude of the location
|
||||||
*/
|
*/
|
||||||
public static void handleGeoCoordinates(Context context, LatLng latLng) {
|
public static void handleGeoCoordinates(final Context context, final LatLng latLng) {
|
||||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, latLng.getGmmIntentUri());
|
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) {
|
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
|
||||||
context.startActivity(mapIntent);
|
context.startActivity(mapIntent);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -545,8 +545,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
* @param place Place of clicked nearby marker
|
* @param place Place of clicked nearby marker
|
||||||
*/
|
*/
|
||||||
private void passInfoToSheet(final Place place) {
|
private void passInfoToSheet(final Place place) {
|
||||||
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
|
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(
|
||||||
place.getLocation()));
|
view -> Utils.handleGeoCoordinates(getActivity(),
|
||||||
|
place.getLocation(), binding.mapView.getZoomLevelDouble()));
|
||||||
|
|
||||||
binding.bottomSheetDetailsBinding.commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
|
binding.bottomSheetDetailsBinding.commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
|
||||||
binding.bottomSheetDetailsBinding.commonsButton.setOnClickListener(
|
binding.bottomSheetDetailsBinding.commonsButton.setOnClickListener(
|
||||||
|
|
|
||||||
|
|
@ -123,10 +123,13 @@ data class LatLng(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a URI for a Google Maps intent at the location.
|
* Gets a URI for a Google Maps intent at the location.
|
||||||
|
*
|
||||||
|
* @paraam zoom The zoom level
|
||||||
|
* @return URI for the intent
|
||||||
*/
|
*/
|
||||||
fun getGmmIntentUri(): Uri {
|
fun getGmmIntentUri(zoom: Double): Uri = Uri.parse(
|
||||||
return Uri.parse("geo:$latitude,$longitude?z=16")
|
"geo:$latitude,$longitude?q=$latitude,$longitude&z=${zoom}"
|
||||||
}
|
)
|
||||||
|
|
||||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
parcel.writeDouble(latitude)
|
parcel.writeDouble(latitude)
|
||||||
|
|
|
||||||
|
|
@ -430,7 +430,11 @@ class LocationPickerActivity : BaseActivity(), LocationPermissionCallback {
|
||||||
else -> null
|
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);
|
updateBookmarkButtonImage(selectedPlace);
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_directions_black_24dp:
|
case R.drawable.ic_directions_black_24dp:
|
||||||
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
|
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation(),
|
||||||
|
binding.map.getZoomLevelDouble());
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_wikidata_logo_24dp:
|
case R.drawable.ic_wikidata_logo_24dp:
|
||||||
Utils.handleWebUrl(this.getContext(), selectedPlace.siteLinks.getWikidataLink());
|
Utils.handleWebUrl(this.getContext(), selectedPlace.siteLinks.getWikidataLink());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue