Google Map Search Link

March 20, 2025 (4mo ago)

I was addng this button in my map where it redirects you to a google map interface so you can explore more of transit options (i.e. directions) It works on the desktop but apparently not on mobile specifically mobile app (android). Not tested in iphone.

Been using several prompts for Claude and ChatGPT but it still returns an incomplete answer. Finally, a good old search in stackexchange gave me a conclusive answer:

    // Encode the name and place_id for URL
    const encodedName = encodeURIComponent(location.name);
    const encodedPlaceId = encodeURIComponent(location.place_id);

    // Construct the Google Maps URL with both name and place_id
    const mapsUrl = `https://www.google.com/maps/search/?api=1&query=${encodedName}&query_place_id=${encodedPlaceId}`;

    // Open the URL
    window.open(mapsUrl, '_blank');