open google maps through intent for specific location in android

后端 未结 12 1111
别那么骄傲
别那么骄傲 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条回答
  •  攒了一身酷
    2020-11-30 20:42

    For the ones, who are looking for opening the "Maps" app for a particular location(by passing lat and long) and do not want that lat/long co-ordinates to be shown in Maps search bar after redirection(Opening Maps app). Instead wish to show some label or place name, you can refer to the code below,

    private void openMapView(String latitude , String longitude , String locationName){
        Uri gmmIntentUri = Uri.parse("geo:"+latitude+","+longitude+"?q="+locationName);
        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
        mapIntent.setPackage("com.google.android.apps.maps");
        if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(mapIntent);
        }
    }
    

    Note : "locationName" in the method above, represents the name you wish to display inside the Maps search bar.

提交回复
热议问题