Please suggest me i am new in android How to Open an inbuilt Google map on button click in android i am having one image button. How to open inbuilt open google map on button click
Asked
Active
Viewed 1.9k times
3 Answers
7
May this helps you.
Example:-
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Uri gmmIntentUri = Uri.parse("geo:0,0?q=");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
}, 1000);
}
});

Shubham Sejpal
- 3,556
- 2
- 14
- 31
3
past this code in onclick listner
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
-
what about sourceLatitude and Longitude its showing error @sagar patel – shubham gupta Apr 05 '17 at 06:59
-
add location latitude and longtitude – Apr 05 '17 at 07:04
-
How sir i dont know – shubham gupta Apr 05 '17 at 07:05
-
if you need to get current position then use Locationmanager class.otherwise direct set Latitude and Longtitude of your address – Apr 05 '17 at 07:08
-
http://mygeoposition.com/ put your address in this link and get lat and long – Apr 05 '17 at 07:10
-
sir we have to declare any variable after getting location – shubham gupta Apr 05 '17 at 07:19
-
Like String sourceLatitude – shubham gupta Apr 05 '17 at 07:19
-
you also use direct without declare variable – Apr 05 '17 at 07:25
-
i want to show only current location but it also asking for destination – shubham gupta Apr 05 '17 at 07:37
-
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); – Apr 05 '17 at 14:18
-
using Above code you can create uri without destination – Apr 05 '17 at 14:21
-
i am getting error – shubham gupta Apr 06 '17 at 04:18
-
FATAL EXCEPTION: main java.util.IllegalFormatConversionException: %f can't format java.lang.String arguments – shubham gupta Apr 06 '17 at 04:18
-
you can try to open the built-in application Android Maps by using the Intent.setClassName method. Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("geo:37.827500,-122.481670")); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); – Apr 06 '17 at 14:49
0
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

Vijay Ankith
- 74
- 7