Directions via Intent Automatically - java

I building an app that contains many addresses. A user can select an address in a listview. This should automatically show a user directions to that address from the users current location.
String uri = "geo:"+ selectedAddress.getLat+","+getLng();
StartActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri)));
I know all this does is show the location of the specified co-ords.
How would i go about showing the directions to the location from the users current location?

How would i go about showing the directions to the location from the users current location?
As #Frxstrem indicated, there is no documented and supported Intent to bring up directions.

ask the user for the place and do the following way:
String place="";//user gives the place.
String url = "http://maps.google.com/maps?daddr="+place;
Intent drn = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
startActivity(drn);
Google will automatically take the current user location as starting point and give directions

Related

PlacePicker Without Opening Widget Screen

I have implemented Google Maps in my App and doing reverse geocoding when clicking on map.Im using This API. but it gives me more than one result on Single tap. I know why Google behave like this.
Then I look into PlacePicker widget for Android, but Im unable to use that widget without opening another Map screen to pick place.
What I want is that I want to use my Google Map screen to get tapped place instead of opening PlacePicker screen. I just want PlacePicker work with my implemented Map i.e want PlacePicker to respond map click and give place without opening widget if this is not possible then inform me about other solution to get exactly one and correct place on Map tap? Thank you in advance
Updated
Why Im getting closed vote for question? it is not too broad? Simply,I want to know whether is it possible to use Google Map (MapView|SuportFragment) as PlacePicker's main screen. Have look code below
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
// I don't want this line, Don't want PlacePicker to open another Map Screen to allow user to pick place.
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
now look at below code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
above code is executed when user pick a place from PlacePicker screen and that screen returns a Intent with picked place. Is there any way to make that type of 'Intent' on Google Map tap with lat,lng? so that I could get Place detail. I don't want to user reverse geocoding as it gives me many results.
I Donot know anything about the google geo api or PlacePicker api.
The google independent android standard way would be to use "ACTION_PICK" with a geo uri.
For more infos see https://github.com/k3b/k3b-geoHelper/wiki/Android-Geo-howto.
This only works if you have installed a geo-pick-aware app that supports geo-pick.
Note: you do not have to use the lib. All you need to do is to decode the geo-uri returned by activity result
I have found solution to my problem, To get rid of reverse geocoding to many results and to get clicked place I use following code
googleMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() {
#Override
public void onPoiClick(PointOfInterest pointOfInterest) {
String SS="";
isPOI=true;
poiPlaceID=pointOfInterest.placeId;
// Then using Google PlaceDetail API with placeId, It gives me exact Location click
}
});

Android Programming - Always Restarts same Intent

I am using Android Studio for a simple communication app and this definitly might be a stupid question but I couldn't find the answer to it yet.
I am simply starting a new intent on a button click. However, the very first time the user does this, he is asked what kind of app he wants to use. Therefore, there are at least two applications with the same intent filter, namely "ACTION_VIEW"
My Problem:
After the initial click the button always "reuses" his initial choice so the user does not have a decision anymore which app he wants to use for this intent.
Unfortunately, this is excactly what I want. The user should get the chance to select the app of his favor each time he clicks on the button.
The relevant part of code is as simple as follows:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Intent.FLAG_UPDATE_CURRENT could probably help you.
https://developer.android.com/reference/android/app/PendingIntent.html
You can use an App Chooser to show the dialog for the user to choose which app to use each time:
[I]f the action to be performed could be handled by multiple apps and the user might prefer a different app each time—such as a "share" action, for which users might have several apps through which they might share an item—you should explicitly show a chooser dialog.... The chooser dialog forces the user to select which app to use for the action every time (the user cannot select a default app for the action).
Intent intent = new Intent(Intent.ACTION_SEND);
...
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title);
// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

How to make my app receive location intents like Google Maps

If you opened a link like this on your android phone Google maps will automatically open and show you the location on it's map.
I want to make my app receive intents if the user opened a link like this and also i want to get the lat,long from that link.
Is this Possible ?
Assuming the link is stored as String variable link
Now,
String[] split_link = link.split(Pattern.quote("#"));
String[] post_link = split_link[1].split(Pattern.quote(","));
double lattitude = Double.parseDouble(post_link[0]);
double longitude = Double.parseDouble(post_link[1]);
Try This!!

Pass latitude/longitude to Google Maps activity and show more than one location in Android and Java

Is it possible to launch google maps activity and pass several latitude/longitude variables so several locations are mapped inside the map? I am able to show one location with this code, but how do I add more parameters?
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", f11, f22);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
But is it possible to show more locations at once? Should I use mapview and how?
Thanks.

How To Show Current Location in URL Custom Google Map by Android Eclipse Project

I Have a Create Android Application With Eclipse , But I Have a Problem ...
I Want to go my custom google map with URl and see device's current location in my map on the device
For Example :
I have a button in one of pages on app , when touch button in the page go to the my custom google map (URL) and show the device's current location.
tanks for your help
Get current Latitude and Longitude using LocationManager.
simply replace the values in the following string with my start and current Lng/Lat
http://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD
Then launch the url like this in android, which will let the user choose to either use the browser or their native maps app:
String url = "http://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD";
startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)));

Categories

Resources