Modern Apps git

← Modern-Apps.git

maps: Google search links run a search instead of pinning a place named after it

Commit
116f72bc24689b4257a6db280dac2b865e05ab50
Author
Vayun Mathur <[email protected]>
When
2026-12-01 11:17 UTC (4 days ago)
Parents
76ebec1
parsePlaceLink merged /place/ and /search/ into an identical
MapLink, erasing the one fact the consumer needs: the
canonical search URL (maps/search/coffee+near+me/@37.77,
-122.41,15z) arrived as query + point, so openPlace dropped
a GenericPlace literally named 'coffee near me' at the
camera centre and opened its sheet — the user never saw
coffee results. The parser's own KDoc already promised the
distinction.

MapLink gains isSearch (true only for /search/ segments);
its coordinates are the bias area, not a place position.
openPlace handles searches first, running the biased search
and selecting the first real hit — the query-only branch's
path. /place/, bare ?q= and coordinate searches are
untouched. Three regression tests pin the three shapes.
Saved places, recents, transit and the archive were audited
and cleared. Verified: :maps:testDevUnitTest 949 tests pass;
lint errors are pre-existing on untouched files.

Diff

maps/src/main/java/com/vayunmathur/maps/MainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/MainActivity.ktindex 569af7f163..b640b2512a 100644--- a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt@@ -209,6 +209,17 @@ class MainActivity : MaActivity() {         val lng = link.lng         val query = link.query         when {+            // A /maps/search/ link: the query is a search, the coordinates only+            // the area it was run from. Run the search biased to that area and+            // select the first real hit — never pin a place named after the+            // search term at the camera centre.+            link.isSearch && !query.isNullOrBlank() -> {+                val near = if (lat != null && lng != null) GeoPoint(lng, lat) else biasPosition()+                searchVm.searchAndSelectFirst(query, near.latitude, near.longitude) { first ->+                    if (first != null) selectedVm.selectAndFocus(searchVm.toFeature(first), link.zoom)+                    else Log.status(TAG, "openPlace: no search result for \"$query\"")+                }+            }             // A point with a name/label → drop it straight in (no network).             lat != null && lng != null && !query.isNullOrBlank() -> {                 selectedVm.selectAndFocus(genericPlace(query, lat, lng), link.zoom)
maps/src/main/java/com/vayunmathur/maps/data/MapLinkParser.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/MapLinkParser.kt b/maps/src/main/java/com/vayunmathur/maps/data/MapLinkParser.ktindex 3d961f96cb..d96fc8a0e5 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/MapLinkParser.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/MapLinkParser.kt@@ -12,6 +12,12 @@ import java.net.URLDecoder  * when it carried one. [navigate] is true for `google.navigation:` and Google  * `/maps/dir/` links, which should START guidance rather than just open a place;  * [mode] is the requested travel mode when the link specified one.+ *+ * [isSearch] distinguishes a search the user ran (`/maps/search/coffee/@…`)+ * from a named place (`/maps/place/Pier 39/@…`): both carry a query string plus+ * camera coordinates, but a search's coordinates are only the area the search+ * was run from — pinning a place literally named after the search term at the+ * camera centre is never what the link means.  */ data class MapLink(     val query: String? = null,@@ -20,6 +26,7 @@ data class MapLink(     val zoom: Double? = null,     val navigate: Boolean = false,     val mode: RouteService.TravelMode? = null,+    val isSearch: Boolean = false, ) {     val hasTarget: Boolean get() = !query.isNullOrBlank() || (lat != null && lng != null) }@@ -166,7 +173,10 @@ object MapLinkParser {                 zoom = zoom,             )         }-        return MapLink(query = query, lat = lat, lng = lng, zoom = zoom)+        // Only a /search/ segment makes this a search: a /place/ name (or a+        // bare ?q=) with camera coords is a named place at those coords.+        val isSearch = place == null && search != null+        return MapLink(query = query, lat = lat, lng = lng, zoom = zoom, isSearch = isSearch)     }      /** One @-coordinate group from the URL, or null. */
maps/src/test/java/com/vayunmathur/maps/data/MapLinkParserSlice3Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/data/MapLinkParserSlice3Test.kt b/maps/src/test/java/com/vayunmathur/maps/data/MapLinkParserSlice3Test.ktindex 00eb4ab1c0..4ddcb8b361 100644--- a/maps/src/test/java/com/vayunmathur/maps/data/MapLinkParserSlice3Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/data/MapLinkParserSlice3Test.kt@@ -119,6 +119,37 @@ class MapLinkParserSlice3Test {         assertEquals("coffee near me", link?.query)     } +    @Test+    fun `web search link with camera is a search not a named place`() {+        // The canonical copied-from-search Google URL: pinning a place named+        // "coffee near me" at the camera centre was the bug; the coordinates+        // are the search's bias area, retained for the consumer's search.+        val link = MapLinkParser.parse(+            "https://www.google.com/maps/search/coffee+near+me/@37.7749,-122.4194,15z",+        )+        assertEquals("coffee near me", link?.query)+        assertEquals(37.7749, link?.lat)+        assertEquals(-122.4194, link?.lng)+        assertEquals(15.0, link?.zoom)+        assertTrue(link!!.isSearch)+        assertFalse(link.navigate)+    }++    @Test+    fun `web place link with camera is not a search`() {+        val link = MapLinkParser.parse("https://www.google.com/maps/place/Pier+39/@37.7749,-122.4194,15z")+        assertEquals("Pier 39", link?.query)+        assertFalse(link!!.isSearch)+    }++    @Test+    fun `web search link for coordinates is still a point`() {+        val link = MapLinkParser.parse("https://www.google.com/maps/search/37.7749,-122.4194")+        assertNull(link?.query)+        assertEquals(37.7749, link?.lat)+        assertFalse(link!!.isSearch)+    }+     @Test     fun `web search with q param and coordinate query becomes a point`() {         val link = MapLinkParser.parse("https://maps.google.com/maps?q=37.7749,-122.4194")