How to open Google Maps using address?

前端 未结 7 1035
野趣味
野趣味 2021-02-07 06:57

How can I open Google Maps(using Intents or adding Google Maps into my application) with address? I have the address, but I don\'t have latitude/longitude. How can I do it? Than

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 07:07

    Little late to the party. I prefer @st0le's answer but URLEncoder.encode(String s) is deprecated as of API 16. You need to pass a second argument as well. Check the answer below.

     public static Intent viewOnMapA(String address) {
        try {
            return new Intent(Intent.ACTION_VIEW,
                    Uri.parse(String.format("geo:0,0?q=%s",
                            URLEncoder.encode(address, "UTF-8"))));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
    

提交回复
热议问题