Reputation:
I need to make an Android app that open Google Map(already installed on my device) and do a search with given text
EX: When I type "Restaurant" in textBox and click button "Search" in my app, it will open Google Maps and search for "Restaurant"
Can anyone help?! Thanks in advance
Upvotes: 2
Views: 893
Reputation: 4037
Make use of the Google Maps Intent to perform this task. Intents help communicate the data from one place to another. In this case its your app and the Google Maps app.
What you need to do is to pass the data that someone has searched in the text box of your app to the Google Maps app directly if its installed. Using geolocation API convert the enterred text into Lat/Lng values. You need to set the package as com.google.android.apps.maps and start the activity.
Here is the full code:
// Create a Uri from an intent string. Use the result to create an Intent.
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988");
// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps");
// Attempt to start an activity that can handle the Intent
startActivity(mapIntent);
For complete documentation read the official page.
Upvotes: 1