简体   繁体   中英

How can I add a source address to google map intent from activity using “google.navigation:ll”?

I want to add a source address in google.navigation:ll . When I am using this it is showing navigation from the current location to the set destination . How do I add a parameter for source address ?

This is my current code line:

double latitudeDestination = 22.5834881; // or some other location
double longitudeDestination = 88.3078827; // or some other location
String requestedMode = "car"; // or bike or car
String mode = "";
if(requestedMode.equals("walking")) {
   mode = "&mode=w";
 } else if(requestedMode.equals("bike")) {
   mode = "&mode=b";
 } else if(requestedMode.equals("car")) {
   mode = "&mode=c";
 }

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse(String.format("google.navigation:ll=%s,%s%s,
                latitudeDestination, longitudeDestination, mode)));
startActivity(intent);

Note: I have followed this link .

The best way to get direction and routes you can use the Web Service of Google Maps . The Google Maps web services are a collection of HTTP interfaces to Google services providing geographic data for your maps applications. These web services use HTTP requests to specific URLs, passing URL parameters as arguments to the services. It will provide you everything. I have used this in my application.

Here is the example where saddr = source address & daddr= destination address . You can also pass string as address instead of lat/lng.

final Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?" + "saddr="+ latitude + "," + longitude + "&daddr=" + latitude + "," + longitude));
    intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
                        startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM