Open map to show direction from current location through intent-Android - android

I have many latitude longitude in my android app. I want to know how to open a chooser or Google map App through intent and show direction from current location to that latitude and longitude.Like i have lat=28.605989,lon=77.372970 and my current location is somewhere so when i click on button in my app these lat lon pass through intent and will show direction from my current location to these lat lon. Thank you.

To navigate user to destination lat long, we can use something like this
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr=28.605989,77.372970"));
startActivity(intent);
Here . we are passing just destination lat long daddr=28.605989,77.372970, so by default, your current location will be source location.
To add extra information with your url .
String my_data= String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=20.5666,45.345(My Destination Place)");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_data));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

You can send intent to Google Map android application by following code:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=22.458,34.34&daddr=75.124,35.448"));
startActivity(intent);
In the above URI saddr represents the source address i.e. your current location and daddr represents the coordinates of the destination location.

Related

How to show distance between two points on map

I have latitude and longutude of two points. I want to show the route between them by opening google maps from my app on button click. How to do so?
Use below code for getting show route in google map...
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("
http://maps.google.com/maps?" +"saddr=" + sourcelatLng + "&daddr=" + destlatlng;
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
If you want to open maps app with a route from your source to destination, you just need to start an activity with following intent.
Uri routeUri = Uri.parse("http://maps.google.com/maps?saddr=your-lat-1,your-lng-1&daddr=your-lat-2,your-lng-2");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, routeUri);
startActivity(intent);
Replace your-lat/lng-1/2 with your latitude and longitude.

My geo location doesn't type on the top of the marker

Whenever I want to type a location name above the marker, it doesn't
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=37.423156,-122,084917(Label+Name)"));
startActivity(intent);
As in this picture http://oi58.tinypic.com/2dgq6a0.jpg
What is the code where I write the text over the marker?

Start Google Map Intent

hi i wanted to make a button which is the button will start google map intent
with my current location and destination location
how to make a google map automaticlly detect my location and destination longitude and lat?
where i put that longi and lat?
i want that map directly draw the direction to destination
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
alr tried this code but not working
Try using one of these with the View intent:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
Something like:
Uri uri = Uri.parse(<ONE OF THE ABOVE STRINGS>);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Try this one:
String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving";
it should work.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=srcLatitude,srcLongitude&daddr=destLatitude,destLongitude"));
startActivity(intent);
// srcLongitude/Latitude = current Location`s longitude/latitude
// destLongitude/Latitude = Destination Location`s longitude/latitude

google map intent not animate to current location in android app...?

I have an android application in which one place I want to call maps.google.com intent and display direction from source to destination.
But when I use this, I want maps animate to direction path automatically.
I use below for calling maps intent
String saddr = "current location";
String daddr = "other location";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
intent call properly and show me maps, and draw path as well but not animate to that place.
Check this link out:
http://developer.android.com/guide/appendix/g-app-intents.html
In your:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr)
try:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr+"&z=10")

How to launch map intent with a marker/overlay item at given latitude and longitude?

I have a latitude and longitude and I want to open google maps centred at that point. So i use the following code for it:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:"+lat +","+lng));
startActivity(intent);
However, this does not place a marker on the center. I want to place some kind of marker at the the point I start with (and optionally some kind of name for it). Any idea how this can be achieved?
You can use it like,
Showing Particular Place,
Uri uri = Uri.parse("geo:0,0?q=22.99948365856307,72.60040283203125
(Maninagar)");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Showing Route between to Places,
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+23.0094408+","+72.5988541+"&
daddr="+22.99948365856307+","+72.60040283203125));
startActivity(intent);
You can simply put latitude and longitude as extras to the intent like this:
Intent intent = new Intent();
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
startActivity(intent);
And then fetch them from the MapActivity you've started:
Intent intent = getIntent();
double latitude = intent.getDoubleExtra("latitude", 0.0);
double longitude = intent.getDoubleExtra("longitude", 0.0);
Then you can use those values for anything you want. Hope this helps.

Categories

Resources