open google maps through intent for specific location in android

后端 未结 12 1115
别那么骄傲
别那么骄傲 2020-11-30 20:17

I\'m designing one application in which I want to show specific location on Map. I\'m passing String of address which is already placed on Google Map

12条回答
  •  Happy的楠姐
    2020-11-30 21:02

    This helper method using uriBuilder for cleaner code and handle condition if there is no activity on device that can open map

    public static boolean openMap(Context context, String address) {
        Uri.Builder uriBuilder = new Uri.Builder()
                .scheme("geo")
                .path("0,0")
                .appendQueryParameter("q", address);
        Intent intent = new Intent(Intent.ACTION_VIEW, uriBuilder.build());
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(intent);
            return true;
        }
        return false;
    }
    

提交回复
热议问题