Changing destination coordinates at runtime (Dynamically) - android

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);
}
});

Related

Get current location start point to uri to start navi

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

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;

How to track facebook current user's location IOS/Android

Is there any way I can track a facebook's user's location in real time who is logged in my mobile app and has location services enabled and also has granted access to my app so as to make use of its location?
Assuming a user X, and 3 linear points in space: A,B,C.
X is traveling from A to C.
Is there an SDK that would enable me to check X's real time location ( latitude + longitude ) at any given time while X is moving from A to C so as to create a dotted map(by dropping a pin on the map) with the user's location at every 10ms?
Is this feasible given the fact that my device has a 4G internet connection?
I think you can use CLLocationManager to update user location after traveling a number of meters. I presume you are already having a CLLocationManager to update your location? you can save the dots in an array (starting with the location of A, ending with location of C). You can then draw a line using the dots. I believe Google Map API has a method for drawing line. There's an answer for that here:
Here is a link from SO
But for the sake of providing code, I will provide it for you in Swift 3.0 (the code in the link is in ObjC):
override func viewDidLoad() {
super.viewDidLoad()
//This is a dummy location, you'd add locations to it using the
// func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
let location:CLLocation = CLLocation(latitude: 200, longitude: 100)
let locationArray:Array<CLLocation> = [location]
let camera:GMSCameraPosition = GMSCameraPosition.camera(withLatitude: (locationArray.first?.coordinate.latitude)!, longitude: (locationArray.first?.coordinate.longitude)!, zoom: 2)
//You can obtain the Lat and Long for above from the list of arrays of locations you saved
//You can use the .first or .last on the array (I used first)
let mapview:GMSMapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
let path:GMSMutablePath = GMSMutablePath()
for nextLocation in locationArray {
if locationArray.index(of: nextLocation) != 0 {
//You dont want to use the first one as you've already done it
//so you start with 1
path.addLatitude(nextLocation.coordinate.latitude, longitude: nextLocation.coordinate.longitude)
}
}
let polyline:GMSPolyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.red
polyline.strokeWidth = 2
polyline.map = mapview
self.view = mapview
//I personally prefer view.addSubview(mapview)
}

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

gps marker on google maps android

I am developing an application which shows the current location of the user. I want to display a marker on the current location of the user.
I have used an image as marker to display current location. But i want to display an animated arrow showing the range just like in the google maps android app. Can anyone please tell me how to achieve this. Any sample code will be of great help...
try this tricky solution...
if u use javascript, try setInterval() to cahnge image if .gif doesn't work.
function runAnimation(callback){
setInterval(function(){
// set new marker here
// var newVal = callback(); <-- use callback to get new value
}
, 500); // interval in millisec
}

Categories

Resources