how to start google map for result - android

I want my user to enter an address. But I want the address to be confirmed with Google Map. So when the user clicks on a button to enter the address, I want to launch an Intent for Google Map where user can enter the address. But then I want the map to return the data to me. How do I do that? If I start my activity as
Uri searchUri = Uri.parse("geo:0,0?z=10&q=");
Intent mapIntent = new Intent(Intent.ACTION_VIEW,searchUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivityForResult(mapIntent,RESULT_CODE_LOCATION);
number one, will it do what I seek? Second: how do I implement onActivityResult? I need the human readable address and the lat-long.
To be clear: I want the user to enter the address through Google Map and then have the address returned to my app.

I figure it out. I have to use PlacePicker to accomplish what I seek. https://developers.google.com/places/android-api/placepicker

Related

set From location to current location in google maps android programmatically

I am creating an app where it requires opening google maps to navigate to a place in walking mode and to set source/from location to current location.
Here is the code I use.
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
How do I set "From location" to "current location"??
Thanks.
I would suggest using a Google Maps URLs instead of the link you provided in the example. The Google Maps URLs is an official and recommended way to launch Google Maps app on mobile devices and web browsers.
Please note that if you omit the origin parameter in the Google Maps URLs, the API will use your current location if available
origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin. The value can be either a place name, address, or comma-separated latitude/longitude coordinates. A string should be URL-escaped.
So, you should rewrite your code as
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
I hope this helps!

Is It Possible To Open Google Maps By PlaceId?

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

Opening directions in Google maps directly

I am using below code to open direction from current location to particular location in Google Maps.
But the code first shows me "Open With dialog" giving user choice to open with other components also. I want user to be taken directly to Google maps without giving him choice to select. How can I do that?
String uri = "https://maps.google.com/maps?f=d&daddr="+location;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
You can use the below format (not officially supported):
https://www.google.com/maps/dir/My%20location/DESTINATION_ADDRESS
OR
https://www.google.com/maps?saddr=My+Location&daddr=DESTINATION_ADDRESS
eg:
https://www.google.com/maps/dir/My%20location/world%20of%20coca%20cola
https://www.google.com/maps?saddr=My+Location&daddr=world%20of%20coca%20cola
Where DESTINATION_ADDRESS is the destination address you want to navigate to.

Android Studio: Location Marker not showing up

The below code is run on an AVD. The AVD browser opens the link through an application and shows google maps, but doesn't display the marker. The browser has the below 'String url' in it's url. When I press enter the url goes to the exact location and creates the marker location. I want to have the browser automatically bring me to the marker location and display a marker without having to click on the url and press enter. Any help is appreciated.
String url = "https://maps.google.com/maps?z=10&t=m&q=loc:"+latitude+"+"+longitude+"";
Uri uri = Uri.parse(Uri.encode(url));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Removed the Uri.encode(url) and it seems to work OK now.

How to check address is correct or not in Android?

I am creating an application in Android where I ask user to enter his address.There are chances that a user can enter wrong address so how can I check that the entered address is correct or not.
Please Help
You could show this address on the map and ask the user to confirm it's correct. Simple example:
var uri = Android.Net.Uri.Parse ("geo:0,0?q=my+street+address");
var mapIntent = new Intent (Intent.ActionView, geouri);
startActivity (mapIntent);

Categories

Resources