I am working on an android app that generate workout location paths as an encoded polyline and I want to display the encoded polyline in Google Maps app with a google map intent (https://developers.google.com/maps/documentation/urls/android-intents)
I post the question in Google Gemini and ChatGPT and got misc responses, but no one working.
Examples (among others) of response returned by Gemini and ChatGPT IA
Google Gemini
String encodedPolylineString = "your_encoded_polyline";
// Decode the polyline (replace with your implementation or use a library)
List<LatLng> decodedPoints = PolyUtil.decode(encodedPolylineString);
// Create the intent
Intent intent = new Intent(Intent.ACTION_VIEW);
String dataUri = "geo:0,0?q=polyline:" + encodedPolylineString;
intent.setData(Uri.parse(dataUri));
intent.setPackage("com.google.android.apps.maps");
// Start the activity (optional)
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
// Handle case where Google Maps is not installed
}
ChatGPT
// Example encoded polyline (make sure to replace this with your actual encoded polyline)
String encodedPolyline = "encoded_polyline_string_here";
// Create the URI for the encoded polyline
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&travelmode=driving&path=enc:" + encodedPolyline);
// Create an Intent from gmmIntentUri
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
// Set the package to ensure that the intent is handled by Google Maps
mapIntent.setPackage("com.google.android.apps.maps");
// Check if the intent resolves to an activity (i.e., Google Maps is installed)
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
} else {
// Handle the case where Google Maps is not installed
// You could show a message to the user or redirect them to install Google Maps
}