Mapbox provides good Navigation SDK for Android, and what I have been trying to do is pass custom lat and lng's to mapbox navigation launcher. But its taking current user location and i would like to pass the custom coordinates . Is that possible?
You need to build a DirectionsRoute and then eventually give it to the NavigationLauncherOptions.Builder.
You can build a route with a custom origin instead of the device location.
Also, you can add custom waypoints.
Create a waypoint via the Point class. Point wayPoint = Point.fromLngLat(longCoordinate, latCoordinate);
Once you get the route from the response, you can eventually give it to the options builder before starting the NavigationLauncher.
Related
I am using Here Map Android SDK. Currently my app can calculate the initial route and draw it through NavigationManager. Listeners are implemented and it will recalculate/redraw when the position changes, but I have a moving target: the destination is another vehicle position I get from a web service at 30 second intervals.
What is the proper way to have the route adjusted for a change in destination?
The easy way is to create a new route with an updated destination waypoint, have it calculated, then replace the old route and its listeners with the new one. I fear this wastes computing resources and produces lag/flicker on the map during the redraw. If this is indeed the path to take, how do we minimize screen issues?
I tried just changing the coordinates of the waypoint but it has no impact. I searched for a "route waypoint change" listener, similar to a traffic or position listener but could not find any.
Update: Since Here confirmed a route destination cannot be updated, I clarify my request for "howto":
What objects can I reuse in the new one? Which objects must we remove from the map and/or destroy to avoid leaks?
Initial plan:
keep handle on waypoint, original route (missing any?)
modify the destination waypoint coordinates
create a new route and have it calculated
move the destination map marker to the new destination
add new route
remove the original route (I assume the beginning of the route is similar in most update cases, so we avoid "flicker")
Anything missing? Listeners handling?
Here SDK does not provide such feature as of today. You can not change existing route or update its target. If you have new destination point you should calculate new route.
I have an issue with android Google Maps. I want find route between two locations but avoid specific points which given in input.
Can you help me with this ?
There is no specific feature of this kind yet. According to this SO thread, this is a feature request for the Maps API.
However,I can suggest possible alternatives like Using Waypoints in Routes.
Note: sample was done in Javascript
In this fiddle demo, you have 3 markers A, B & C.
A = origin, B = route, C = destination.
var directionsService = new google.maps.DirectionsService;
Let's say the initial point of B is blocked, drag it to other streets/points in the map (zoom-in to see other routes) and you have your alternative route. You can read more of waypoints in the DirectionService guide.
I have mapped my current location and also 4 other locations on my map.Is it possible the mark the route which is closest to the current location(1),then from that(1) to the next closest(2) position,then so on(3).!!Finally i should have the route from my current location marker via all the location in between(markers) till the last marker!!
Thanks in advance!!
You are going to have to use separate instance of DirectionsService object to make your directions request for each destination and then set that to the map using the same instance of the DirectionsRenderer object.
Take a look at this JSFiddle
There are three separate directions in this example. Just make the start the same location.
I'm developing a android application with google maps v2 that draw polygons on the google maps. But now i have to identify a click on a certain polygon and popup a window.
I found this useful library on github
This library has the method containsLocation implemented. This method receives a LatLng (from click on the map) and a List (the polygon). This is fine but if i have 1 million polygon in the map i cant iterate all and test if a certain LatLng belongs to a certain Polygon. I remember that i can use a quadtree to get more performance and this library also implements a quadtree but it uses point. What is the best way of doing this? May i have to reimplement this quadtree for a quadtree of LatLng ? Or in each click i have to convert this click to a point and search on a point quadtree?
Regards
you cannot use a Point- Quadtree, you need an Object-Quadtree for your Polygons. An object quadree uses the bounding box of the polygon or any object for adding into the tree.
you dont need to consider latLong, use x,y with x= longitude, and y = Latitude.
Consider reading Hanan Sammet: Foundations of multidimensional data structures.
I think you need to implement a quadtree that stores the polygons, then query the tree to see which polygon (if any) contains the LatLng. If you search around I'm sure you can find a decent implementation.
Im developing a map app in which gps detects my current location and places a marker.Using spinner I get nearby places based on category.What I need is,When I longclick the marker of spinner,Using intent it should show the step by Step navigation instructions in a new page also it should draw route ie polyline from my location to the touched location.
I used http://wptrafficanalyzer.in/blog/showing-nearby-places-and-place-details-using-google-places-api-and-google-maps-android-api-v2/ code for abvove purpose.
Please Help..Thanks in advance.
You can take a look at this blog post I wrote on drawing the navigation on the map:
Google Maps V2 for Android: Draw Driving Direction on Map
For adding the Step by Step navigation I guess you would need to change the parsing method a bit in order to get this info from the JSON file you receive.