How to open a mobile device's map app when a user clicks on a link?

前端 未结 7 1952
南旧
南旧 2020-12-23 01:56

I have a web app where if a user clicks on a link it should open up a map. The best solution that I can think of is to open up a new tab/window to google maps using the

7条回答
  •  春和景丽
    2020-12-23 02:34

    For me, the best answer was to standardize a map tag, such as "MAP:".

    Then to make an address invoke maps, preface it with MAP:.

    So to tell a friend where something is, use something like: Map: 123 any street PA 98234.

    Then when the address is clicked (for a phone, tapped), the default mapping app is invoked.

    Added from comment:

    The idea was for e-mail and texting, however if you want a code example, this works on android:

    try
    {
        String uri = "geo:0,0?q=" + Address;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplicationContext().startActivity(intent);
    }
    catch (SecurityException es)
    {
        if (LOG) Log.e("Dbg", "Map failed", es);
    }
    catch (ActivityNotFoundException e)
    {
        if (LOG) Log.e("Dbg", "Map failed", e);
    }
    

提交回复
热议问题