Reputation: 710
i want to show one location in google map, for that i used the below code:
String geo = maindata.getString("map");
String uri = String.format(Locale.ENGLISH, geo, "", "");
final Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
try {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
cordova.getActivity().startActivity(intent1);
}
});
}catch(Exception e){
e.printStackTrace();
}
The google map application is getting launched and it is showing proper location also, BUT the problem is, when press back button then it is restarting my application.
whereas i want to resume from the lunching position
Upvotes: 0
Views: 182
Reputation: 21
You can display particular location on google map by using following code snippet:
Uri gmmIntentUri = Uri.parse("google.navigation:q=" + lattitude+ ","
+ longitude+ "+&mode=d");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
if (isAppInstalled("com.google.android.apps.maps")) {
mapIntent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
}
startActivity(mapIntent);
Here latitude and longitude belongs the location which you want to display on map.
/**
* helper function to check if Maps is installed
**/
private boolean isAppInstalled(String uri) {
PackageManager pm = mActivity.getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
And on back press from google map user will redirect to the same activity from which google map was launched.
Upvotes: 1
Reputation: 84
You have to put your activity to the buttom of the stack and then launch the Google map app activity
do the following :
String geo = maindata.getString("map");
String uri = String.format(Locale.ENGLISH, geo, "", "");
final Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
try {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class); //Instead Of MainActivity you can add your Launching activity Name
stackBuilder.addNextIntent(intent1);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
startActivity(intent1);
}
});
}catch(Exception e){
e.printStackTrace();
}
Upvotes: 0