So I am building a map that shows locations (markers). I don't want to use the Map ToolBar (which has directions and open in Google Maps button) however I do want to make my own button that opens in GoogleMaps with directions to that marker.
try this:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
Or if not working try this according to this link https://developers.google.com/maps/documentation/urls/guide:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393"));
startActivity(intent);
Related
I'm launching Google Maps in Android from a particular view in my app layout like this:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
view.getContext().startActivity(mapIntent);
Once I'm done with the maps and return to my app, the maps app is being launched again when I click anywhere (not just that particular view) on my app.
How do I stop this from happening?
I need maps to launch only when a particular view is displayed.
Try to call finish(); and return(); after you are starting the intent
something like this
Intent mapIntent = new Intent(Intent.ACTION.VIEW,loaction);
view.getContext().startActivity(mapIntent);
finish();
return;
i am working with Google Maps navigation in my Android application ...
When calling Google Maps navigation's Intent from MainActivity Google Map Showing route path completely in my device but now when press back button from Google Maps it close whole application instead go back to MainActivity so i need to go back my MainActivity on Back pressed in Map activity...
My code for calling map activity
String strURL = new StringBuilder()
.append("http://maps.google.com/maps?saddr=")
.append(src_lat).append(",").append(src_long)
.append("&daddr=").append(dest_lat).append(",")
.append(dest_long).toString();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(strURL));
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent);
Can any one help me ??? how to catch back pressed event from Google Maps navigation's Intent ...
You should use startActivityForResult(); and make sure your activity doesn't have any propertly like singleinstance or singleTop.
I want to launch the Google Maps app from my android application with the driving directions view.
I gone through the following posts but they don't serve my purpose.
Launch Google Maps to show road directions
How to programmatically launch map appliction in android to show direction?
I tried the following code...
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?f=d&daddr=51.448,-0.972"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
Which gives me the following view,
Then I need to click 'Get Directions' button to get the following view,
And then I need to click 'DIRECTIONS LIST' to get the following view,
Is there a way to directly launch the 3rd view (as above) from my android application?
Yes You can directly open direction view Using google.navigation.
Just pass Destination address and it will give direction from current location to destination address:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=destination address"));
startActivity(intent);
How can i start an Intent to open either the default navigation application (e.g. Google Navigation or Google Maps) or give the user the opportunity to select among navigation applications.
Thanks in advance.
You have to use an Intent with ACTION_VIEW and the geo data scheme.
The problem using geo:latitude,longitude is that Google Maps only centers at your point, without any pin or label.
That's quite confusing, especially if you need to point to a precise place or/and ask for directions.
If you use the query parameter geo:lat,lon?q=name in order to label your geopoint, it uses the query for search and dismiss the latitude and longitude parameters.
I found a way to center the map with latitude and longitude and display a pin with a custom label, very nice to display and useful when asking for directions or any other action:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
startActivity(intent);
This intent is from the list of official "G apps" intent list here.
Try:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); startActivity(i);
Or use this, this way the stardard navigation app will be launched:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
Add this line before startActivity if you don't want the popup dialog:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
Also see: How to check programmatically if an application is installed or not in Android? and Android: detect when app is installed, you can make your own Window so the user can choose between some application.
i am developing android app to get direction between 2 location, as below
Intent intent = new Intent(android.content.Intent.ACTION_VIEW;
Uri.parse("http://maps.google.com/maps?saddr=12.84281852,80.22529753&daddr=13.00355419,80.200881958"));
startActivity(intent);
Running this application, it is prompting me to choose one among 1) Browser 2) Map
How to open it in map by default in coding??
I think if you call setPackage() with 'com.google.android.apps.maps' it should launch Google maps.
This worked fine for me:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);