I am new to android and developing a navigation based application for android.My question is I want to show a route with multiple way-points between source and destination node in Google maps and I don't know how to do it. I have search for this but most of the results are for two points.
Please help me to solve my problem
e.g:- when app user submits the destination with some way-points the map should display the route from the source to destination with those way-points on the phone.
Thanks !
I don't think the Maps intent offers those capabilities, but you do have some other options
Better but more work
1)Create your own map activity that displays routes for multi-location(using a mapview and overlays). Here is an example of how to convert the kml file to a route
Quicker and Easier
2)Create a simple webview (or you can just intent a new one with a given url) and dynamically build the url for a google maps api request with waypoints. See Google's website for documentation on getting a map with routes via waypoints.
"I have search for this but most of the results are for two points." You already found everything you need to do this.
For this, you're not "drawing through the waypoints along the way," you're actually going to have to draw a route between 2 points for each waypoint you have:
IE. You want to get from point A to point D, and on the way there are points B and C. The solution is to draw a route from A to B, B to C, and finally C to D.
You can use the map intent like this:
String address = "http://maps.google.com/maps?daddr=" + "Latitude" + "," + "Longitude" + "+to:" +"Latitude" + "," + "Longitude";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
startActivity(intent);
in this case the start point will be your current location and you can add as many intermediate points as you want using "+to:"
Related
I'm pretty much on the last step to getting my app to work before I start focusing on the front-end design. As someone who just started programming just last year and haven't made any serious apps before, this is very exciting, but I hit a wall that I need help getting out of. I know this is a stretch but here goes.
I was able to use the google maps API and OSRM API with no problems using the simple URL object from java.net.URL, but that was because the APIs did not require any type of OAuth authentication.
Link
For Yelp's API, I need to use OAuth and they provide sample code located here
I copied both YelpAPI.java and TwoStepOAuth.java and the search works when I try searching by location name. However, I need to change the code to work with lat/long coordinates.
https:// www.yelp.com/developers/documentation/v2/search_api
By going to their Search API documentation, I thought that replacing:
request.addQuerystringParameter("location", location);
with
request.addQuerystringParameter("ll", coordinate);
where coordinate can be any lat/long coordinate such as
String coordinate = 34.095287, -118.1270146
However, that did not work. I'm not sure where to go at this point. I've been stuck on this issue for two days and I'm unable to find any resources online to help me. Thanks for reading.
to search yelp data by lat, lng I use the below method
public String search(String term, double latitude, double longitude) {
OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.yelp.com/v2/search");
request.addQuerystringParameter("term", term);
request.addQuerystringParameter("ll", latitude + "," + longitude);
this.service.signRequest(this.accessToken, request);
Response response = request.send();
return response.getBody();
}
Now all you just need is to cast your string co-ordinates to double.
I am creating an app where I need to start the navigation app and then use the result (most importantly the driven distance). I am starting the navigation activity with startActivityForResult and using the scheme "google.navigation". Like this:
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=Somewhere"));
startActivityForResult(i,1);
This works great, I get a callback when the activity is done, but the data portion of the activity is empty.
Is there a way to do this?
Is there a navigation history where I can browse the latest trip for data?
Best Regards
Jakob Simon-Gaarde
Is there a way to do this?
No, there is no way for you to force an activity to give you a result. The determination of whether an activity supports a result lies in the authors of the activity, not the caller of the activity.
Is there a navigation history where I can browse the latest trip for data?
There is no documented and supported API for the Google Navigation Android app (which includes the google.navigation scheme).
I don't know about callbacks from Google Navigation. But if you are only interested in getting the driven distance, you could keep listening to the location updates in the background and calculate the distance yourself. The following function uses android.location.Location to calculate distance between two LatLang coordinates:
public double getGeodesicDistance(LatLng from, LatLng to){
Location _fromLoc = new Location("From location");
_fromLoc.setLatitude(from.latitude);
_fromLoc.setLongitude(from.longitude);
Location _toLoc = new Location("To location");
_toLoc.setLatitude(to.latitude);
_toLoc.setLongitude(to.longitude);
return Math.round(_fromLoc.distanceTo(_toLoc)); // distance in metres
}
But if you decide to take this approach, you should detect the sudden jumps in GPS data and handle them accordingly.
You could get the location right before you start the navigation, and get it again once the navigation is closed, and calculate the difference.
I went through lots of links but I am getting confuse about getting direction on Google map.
When my apps get start it shows user's current location, and when user click on hospital logo which is on map, it will shows all hospitals within 5 km with user's current location. When user click on any places hospital he get information about it.
Now my point is I want to show direction from current location to hospital which is touched by user.
I am using google map API of v2.
Please give me the way through which I can achieve this task...
try this
try {
Intent directioIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + strSourceLatitude + "," + strSourceLongitude + "&daddr=" + strDestinationLatitude + "," + strDestinationLongitude));
directioIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(directioIntent);
} catch (Exception e) {
Utilities.showToast(GetDirectionActivity.this, "Google Map is not installed on your device.");
}
Checkout this blog post I wrote on painting a Polyline on Google Maps API V2 to draw direction from one location to another:
Google Maps API V2 Directions
you will find the the relevant methods to get you started.
I am displaying a location on Google map by passing latitude longitude values.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:0,0?q=" + (" "+dblLatitude+", "+dblLongitude+" ")));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
setContentView(R.layout.map_locate);
}
Its working fine for me. But I also want to show text on above the located point. Any idea how to pass the text dynamically like I am passing lat, long values?
To show a label on Google Maps application you have to add it in brackets after coordinates.
See this answer: https://stackoverflow.com/a/7405992/2183804
You can put extra data into the intent object using e.g. the putExtra(String,String) method on the intent object.
As you firing an intent to turn on the native Google Maps Application. I don't think that what you are trying to achieve is possible. AFAIK all you can add to the desired location is an icon.
If you want to add to it more functionality you would have to develop your own map application.
UPDATE:
To develop you own map, you can take a look at this blog post I wrote on that matter:
Google Maps API V2
If you have questions don't hesitate to ask.
Im having problems porting some functions of Iphone application to Android.
Basically iphone google map app that is invoked from this app looks like this
I have tried to copy similar behaviour using this pseudo code
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+LAT_POSITION+","+LONG_POSITION+"&daddr="+Lat+","+Lon + "&dirflg=w"));
startActivity(intent);
what it does it brings the android map app in this form
so then when i click show map i get
and then when i press back twice i get this
my questions are.
How I can get the (car,public,walk) controls overlay the map? just like in iphone app - on one screen (other elements too if possible)
additional question..
How I can enable showing map by default? (instead of textual directions, this is happening in android 2.2 - I have checked on samsung galaxy with froyo) , In 4.0 (emulator) the map is showing by default but still there are no overlay controls (car,public,walk).
You can use setComponent to explicitly tell the Maps app to use com.google.android.maps.MapsActivity to resolve the intent:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + LAT_POSITION + "," + LONG_POSITION +
"&daddr=" + lat + "," + lon + "&dirflg=w"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
You should get the directions overlay but I'm not sure it will draw the route until the user hits "Go".
Of course this is "non API" and assumes that Maps is installed on the device and that Google will not change the internal packgage or class name for MapsActivity.