Get current location start point to uri to start navi - android

I finally found out on how to add more locations to my route in uri:
Example:
Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://www.google.com/maps/dir/48.8276261,2.3350114/48.8476794,2.340595/48.8550395,2.300022/48.8417122,2.3028844"));
StartActivity(intent);
The problem is that I only see Preview button and not Start to start navigate.
I think it's due to the fact that the first point is not the current location.
Does anyone knows how to set up the first point as the starting point where I am currently, to have the possibility to start navigation?

Maybe the dir_action=navigate parameter setting will be close to what you want.
In the official Google Maps documentation, the section on Forming the Directions URL in Developer Guide talks about how to navigate using Intent.There are dir_action=navigate and waypoints in parameters to set the navigation mode and intermediate waypoint settings. If you need to start from the user's starting point, then the origin parameter can be (original to most relevant starting location, such as user location, if available.)
https://www.google.com/maps/dir/?api=1&parameters
origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin.
dir_action=navigate (optional): Launches either turn-by-turn navigation or route preview to the specified destination, based on whether the origin is available. If the user specifies an origin and it is not close to the user's current location, or the user's current location is unavailable, the map launches a route preview. If the user does not specify an origin (in which case the origin defaults to the user's current location), or the origin is close to the user's current location, the map launches turn-by-turn navigation. Note that navigation is not available on all Google Maps products and/or between all destinations; in those cases this parameter will be ignored.
waypoints: Specifies one or more intermediary places to route directions through between the origin and destination. Multiple waypoints can be specified by using the pipe character (|) to separate places (for example, Berlin,Germany|Paris,France). The number of waypoints allowed varies by the platform where the link opens, with up to three waypoints supported on mobile browsers, and a maximum of nine waypoints supported otherwise. Waypoints are displayed on the map in the same order they are listed in the URL. Each waypoint can be either a place name, address, or comma-separated latitude/longitude coordinates. Strings should be URL-escaped, so waypoints such as "Berlin,Germany|Paris,France" should be converted to Berlin%2CGermany%7CParis%2CFrance.
Examples from your data:
Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://www.google.com/maps/dir/?api=1&origin=48.8276261,2.3350114&destination=48.8417122,2.3028844&waypoints=48.8476794,2.340595|48.8550395,2.300022&travelmode=driving&dir_action=navigate"));
StartActivity(intent);
If want defaulf from current location:
Uri is : "https://www.google.com/maps/dir/?api=1&origin=&destination=48.8417122,2.3028844&waypoints=48.8476794,2.340595|48.8550395,2.300022&travelmode=driving&dir_action=navigate"
Here's an official method to help you test if your destination is within planning and automatically start from your current location:
Android.Net.Uri gmmIntentUri = Android.Net.Uri.Parse("google.navigation:q=48.8417122,2.3028844");
Intent mapIntent = new Intent(Intent.ActionView, gmmIntentUri);
mapIntent.SetPackage("com.google.android.apps.maps");
StartActivity(mapIntent);
You can modify q=48.8417122,2.3028844 to your want test destination data.
If want to modify location of simulator , look at the screenshot below:

You can use this:
String mapsUrl = "https://www.google.com/maps/dir/?api=1&origin=48.8276261,2.3350114&destination=48.8476794,2.340595&waypoints=48.8550395,2.300022|48.8417122,2.3028844&travelmode=driving&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mapsUrl));
startActivity(intent);
Where
origin is your starting point
destination is your ending point
waypoints is your stops
you should add waypoint with using |
example: waypoints=48.8550395,2.300022|48.8417122,2.3028844
You can also add travelmode to specify travel mode
These are travel modes that you can use: driving,bicycling,transit,walking
This will open Google Maps in driving mode

Related

Mapbox Navigation via Customised Routes

So Mapbox provides an awesome Navigation SDK for Android, and what I have been trying to do is create my own routes, representing each point as a Feature in a Geojson file, and then passing them on to the MapMatching module to get directions that I can then pass to the Navigation Engine.
My solution evolves into two main parts. The first one involves iterating through the points I want navigation to go through, by adding them as input to the .coordinates element of MapboxMapMatching.builder() and subsequently converting this to
.toDirectionRoute(); per Mapbox instructions and example here: https://www.mapbox.com/android-docs/java/examples/use-map-matching/
private void getWaypointRoute(List<Point> features) {
originPosition = features.get(0);
destinationPosition = features.get(features.size() - 1);
MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(features)
.steps(true) // Setting this will determine whether to return steps and turn-by-turn instructions.
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>() {
#Override
public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
if (response.body() == null) {
Log.e(TAG, "Map matching has failed.");
return;
}
if (response.isSuccessful()) {
currentRoute = response.body().matchings().get(0).toDirectionRoute();
The second bit involves just passing 'currentRoute' to the NavigationLauncher as shown below:
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.origin(origin)
.destination(destination)
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.enableOffRouteDetection(false)
.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(MainActivity.this, options);
An example of the route can be seen here Android Simulator Snapshot with Route . Each point across the route, is an intersection, and corresponds to a feature in my GeoJson file. The problem becomes when I launch the navigation. Every time, either in the simulator or on a real device, each point is interpreted as a destination so the voice command goes 'You have reached your first (second, third etc) destination'. I find this annoying as I would like to have a single route with a destination and that's it. I would just like to have this points so I have my own custom path, instead of the shortest path typically returned by routing applications. I try to avoid the problem by setting voiceInstructions off but then the system goes bananans and the navigation screen moves to lat, lng (0,0) which is pretty much somewhere West of Africa. Any help on how I could resolve this it would be greatly appreciated and I would be happy to buy a beer or two for the person that provides the right answer. I have reached out to Mapbox Support as well but we have not found an answer to the problem so I asked them to escalate it internally within their engineering team, as I believe, although the problem I am solving is not uncommon, it is still not very much tested by developers. Cheers!
So here I am and after the kind support of Mapbox Support and Rafa Gutierrez
I can now answer this post myself.
The problem has been arising due to MapboxMapMatching automatically setting .coordinates as waypoints. If instead, one edits explicitly the waypoints variable to have only two waypoints: origin and destination, then the system is able to process the input customised route without translating each input coordinate as a waypoint. The code example below hopefully clarifies the point described above:
MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(lineStringRep.coordinates())
.waypoints(OD)
.steps(true)
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>()
where OD is an array of integers storing the first (origin) and last index (destination) of your coordinates
OD[0] = 0;
OD[1] = features.size() - 1;

Changing destination coordinates at runtime (Dynamically)

I want to program an Android application where user A can navigate it self to user B (using Google Maps and their Navigator).
But I want my android application to update the coordinates of user B and send it to user A in real time.
My question is: Are there any way for user A to retrieve the updated coordinates AND not getting a new route calculated every time that user B change its position?
Since I want my user B to send new coordinates every 15 meters, it would be hell if user A gets a new route calculated every time.
You can use setDirection() method on the renderer and pass it to DirectionsResult. The DirectionsResult contains the result of the directions query, which you may either handle yourself which can automatically handle displaying the result on a map. The renderer is an MVCObject, it will automatically detect any changes to its properties and update the map when its associated directions have changed.
The following example calculates directions between two locations on Route, where the origin and destination are set by the given "start" and "end" values in the dropdown lists. The DirectionsRenderer handles display of the polyline between the indicated locations, and the placement of markers at the origin, destination and any waypoints, if applicable.
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: 'DRIVING'
};
directionsService.route(request, function(result, status) {
if (status == 'OK') {
directionsDisplay.setDirections(result);
}
});

Skobbler 2.5.1 on Android occasionally routes to viaPoints incorrectly.

I have an example route that I've tested using the Skobbler SDK.
Start Point: around 820 S MacArthur Blvd
Irving, TX 75063
End Point: Bass Performance Hall, Fort Worth, TX
Via Point #1: Shell Gas Station, 1224 Oakland Blvd Fort Worth, TX
The code that's used to calculate the route is as follows:
SKRouteSettings route = new SKRouteSettings();
// set start and destination points
route.setStartCoordinate(start);
route.setDestinationCoordinate(end);
route.setNoOfRoutes(1);
// set the route mode
route.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST);
// Traffic enabled
route.setUseLiveTraffic(true);
route.setUseLiveTrafficETA(true);
route.setTollRoadsAvoided(true);
route.setAvoidFerries(true);
route.setHighWaysAvoided(true);
ArrayList<SKViaPoint> viaPoints = new ArrayList<SKViaPoint>();
viaPoints.add(new SKViaPoint(VIA_POINT_ID_OTW_DEST, viaPoint));
route.setViaPoints(viaPoints);
// set whether the route should be shown on the map after it's computed
route.setRouteExposed(true);
// Set traffic routing mode
SKRouteManager.getInstance().setTrafficRoutingMode(SKMapSettings.SKTrafficMode.FLOW_AND_INCIDENTS);
// set the route listener to be notified of route calculation
// events
SKRouteManager.getInstance().setRouteListener(this);
// pass the route to the calculation routine
SKRouteManager.getInstance().calculateRoute(route);
When I compute this route via the Skobbler SDK and display the calculated route on the SKMapView, I sometimes get a route that doesn't make sense.
This route calculated on one of our test devices shows the calculated route taking us off the freeway, turning right onto a street and then making a u-turn at the end of the street, before turning right again into the Shell gas station. For some reason, the routing algorithm is not realizing that the route can go straight off the freeway and then turn right, or alternatively, turn right at the street off the freeway and then make an immediate left.
This is not the only instance of incorrect routing that we have witnessed, but it is the most recent. In the past, we have been able to make slight modifications to the coordinate passed for the via point to make the routing algorithm return a sensible route, and then were able to go back to recalculating the original route correctly without the long detours.
In this case, in order to view the corrected route below, we simply try routing the same route again some time later:
Has anyone experienced an issue similar to this and is there something that can be done on the client side to prevent it? Or perhaps a request setting that can be made while requesting a route calculation to the server that might help?
Thanks for any feedback on the matter!
-Keith

Android - To draw a route between two geo points

In my direction class I have two geo points.One corresponds to current position and other is a fixed geo point.Current position will keeps changing.I need to draw route between these two points and need to change this line for a change in distance of 500m.
I think best solution is called android internal map activity to show route between two geo points . Please refer below code.
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
It called built in map activity and draw a route path between current and fixed latitude and longitude.
#Siraj May be this link will help you to find how you can achieve your goal .you can use your start point and End point lat and long to draw path in your own map .use this link for Geocoding API click here
For Draw path refer this link for Draw Path

Google Maps advanced features in a MapActivity (Google Maps API)

I wanted to load a custom KML file on the map. I chose the simple way:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, url);
And it works well, but obviously I can't control various features like custom icons for overlay items, or the popup "Loading myKml.kml..." that shows everytime I start it, etc.
First question:
Aren't there any parameters to setup when I start a Google Maps Intent, to tweak my map? I can't find anything on the documentation.
So I was thinking about using the Google Maps API for my app. Well, I've managed to load my KML file parsing it with a SAX parser and creating a custom overlay for my map.
It works, but there is a great problem:
The placemarks aren't loaded dynamically in relation to my position. They are loaded from the start to the end, and are shown on the map 100 at time.
So it was going to be harder than I thought, because I'll have to get my position from the GPS and calculate only the nearest points and draw them on the map.
Second question:
Does exist a built-in function to show only near-to-me placemarks on the map?
Thank you, guys.
2nd question. No. Have a look at LocationManager.addProximityAlert(double latitude, double longitude, float radius, long expiration, PendingIntent intent).

Categories

Resources