![]() ![]()
#Launching an google maps navigation intent android studio updateOnce you have imported these libraries and synced the project, you need to update the layout file for MainActivity.java so that it uses the custom fragment shown below. I should note that the Google Maps Utils library is technically still in beta, though it has been available for the last two years. compile ':play-services-maps:7.8.0'Ĭompile ':android-maps-utils:0.4' Next, open adle and add two new dependencies, one for Play Services to use Google Maps and another one for the Google Maps Utils library. ![]() For this tutorial, you need to get an API key and set up your project with a manifest as described there. ![]() #Launching an google maps navigation intent android studio how toIn the first tutorial of this series, I went over how to set up a project using the Google Developer Console and adding an API key to your manifest. The source files for this tutorial can be found on GitHub. In this tutorial, you will learn how to use this utility library to add heat map visualizations for your data, cluster large numbers of markers for easier viewing, and use various utility methods for working with the spherical nature of the Earth or drawing routes on roads. Luckily, Google has created an open source library containing a set of utilities that Android developers can use to make their applications even better with enhanced maps. See also Intent for Google Maps 7.0.While the standard features of Google Maps are incredibly useful, there will be times that you want to do a little bit more. Will ignore the coordinates and search for an object with the given name between the parentheses. NOTE (by Not working in Maps v.7 (latest version at the time of writing). I found a way to center the map with lat/lon 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(_VIEW, 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 lat/lon parameters. That's quite confusing, especially if you need to point to a precise place or/and ask for directions. The problem using "geo:latitude,longitude" is that Google Maps only centers at your point, without any pin or label. This is a little off-topic because you asked for "directions", but you can also use the Geo URI scheme described in the Android Documentation: Intent mapIntent = new Intent(Intent.ACTION_VIEW, navigationIntentUri) #Launching an google maps navigation intent android studio installToast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show() Īny latitudes or longitudes used in my example are not representative of my location, any likeness to a true location is pure coincidence, aka I'm not from Africa :Pįor directions, a navigation intent is now supported with google.navigation Uri navigationIntentUri = Uri.parse("google.navigation:q=" + 12f " +"," + 2f) Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)) String uri = String.format(Locale.ENGLISH, " (%s)", 12f, 2f, "Where the party is at") To use your current location as the starting point (unfortunately I haven't found a way to label the current location) then use the following String uri = String.format(Locale.ENGLISH, " (%s)", destinationLatitude, destinationLongitude, "Where the party is at") įor completeness, if the user doesn't have the maps app installed then it's going to be a good idea to catch the ActivityNotFoundException, then we can start the activity again without the maps app restriction, we can be pretty sure that we will never get to the Toast at the end since an internet browser is a valid application to launch this url scheme too. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)) String uri = String.format(Locale.ENGLISH, "(%s)&daddr=%f,%f (%s)", sourceLatitude, sourceLongitude, "Home Sweet Home", destinationLatitude, destinationLongitude, "Where the party is at") Although the current answers are great, none of them did quite what I was looking for, I wanted to open the maps app only, add a name for each of the source location and destination, using the geo URI scheme wouldn't work for me at all and the maps web link didn't have labels so I came up with this solution, which is essentially an amalgamation of the other solutions and comments made here, hopefully it's helpful to others viewing this question. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |