In my Android application I am working with Google Maps, where I want to search for a particular address for example "Apple Office". So I found the current location and need to search for "Apple Office" within five km of the current position. So my address is already marked in Google Maps. I know how to search for a location
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
This will search for San Francisco... but I need to search with text. So what change do I need for that?
You have to use 'Google Places API for Android'. https://developers.google.com/places/android-api/
Related
I'm creating a local guide app on android, and I want to set an onItemClickListener to my array that will open google maps with filled search text. For example: In shopping category, there are stores like ZARA H&M. So, I want to create an Intent that will open google maps with search text "ZARA near me" etc.
Can anyone help me with it?
Thanks in advance.
You can pass the lat, lon of the area you are interested like so:
// Search for restaurants in San Francisco
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?q=restaurants");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Or by address like so:
Uri gmmIntentUri = Uri.parse("geo:0,0?q=1600 Amphitheatre Parkway, Mountain+View, California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Taken from the Google docs.
I am implementing an app that provide navigation from current location to another. For that I have used Google turn-by-turn navigation. But some devices show different end points for the same address. I have attached screenshots of two different devices. The destination address is 5121 Rhoads Avenue, Santa barbara, CA, USA
This is the code I'm using
Uri gmmIntentUri = Uri.parse("google.navigation:q=5121 Rhoads Avenue, Santa barbara, CA, USA");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Device A results
Device B results
I have a place id obtained from Google Places API, and the aim is opening Google Maps app via place id like similar approach of below
Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", lat, lon));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
Is there a way for this ?
I have already latitude, longitude when user type for example "Eiffel Tower" from places API. And I'm storing those values for next usages(Say we are listing some sort of visited places from local database, and user click one of them and app navigates to Google Maps)
I have a few concerns
If i use latitude-longitude to indicate a place instead of place id
on Google Maps, what will happen if "Cafe XYZ" moved another street
?
If i use place id each time to receive last location of "Cafe XYZ"
(instead of stored values in my local database) the app easily hit request limits
So those concerns made me think a way that just sending place id Google Maps(like sending coordinates)
Indeed, there is a way to open Google Maps app with a place ID. For this purpose you have to use Google Maps URLs that was launched in May 2017. Following the documentation of Google Maps URLs you can construct the following URL for "Eiffel Tower" (place ID ChIJLU7jZClu5kcR4PcOOO6p3I0)
https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0
So, your code will be something like
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
I hope this helps!
It's probably super late but I was able to make it work with info we should have aside from the LatLog
Searching for CenturyLink Field using latitude/longitude coordinates as well as the place ID results in the following map:
https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393&query_place_id=ChIJKxjxuaNqkFQR3CK6O1HNNqY
How can I launch route activity on google maps from my app without specifying the destination? I am using:
Uri gmmIntentUri = Uri.parse("google.navigation:q=<>");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Bad behavior :
But the "to" field in google maps has "<>" string, and if I write:
Uri gmmIntentUri = Uri.parse("google.navigation:q=");
But this not working.
The idea is:
Right behavior:
There doesn't seem to be a way for you to specifically go to a specific Activity in the official Maps app (empty destinations). If you look at the Google Maps Intent, it exposes several intents that can launch Maps to display, search, navigate and use Street View. For searching location, you are required to have coordinates or optional queries and labels.
I want know if it's possible to launch the Google navigation to a specific location by providing GPS coordinates of that location from an application.
If you mean you want to launch google turn by turn navigation from your application by providing latitude & longitude coordinates, then here is the code:
public void launchNavigation(){
String location = mLat + "," + mLng;
Uri gmmIntentUri = Uri.parse("google.navigation:q="+location);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
Basically in the Uri parameter you can pass either street address or Lat,Lng like the following:
google.navigation:q=a+street+address
google.navigation:q=latitude,longitude
I hope this could help someone with the same problem as I guess your problem would have been resolved long ago.