Issue in passing multiple way points to Google map API - android

I am trying to pass multiple way points between an origin and destination, so that when I get the response I can draw the route on Google map.
This is a sample call I make (in my original API call, there are more way points):
https://maps.googleapis.com/maps/api/directions/json?origin=41.3758887,2.1745799999999917&waypoints=41.39097711845494,2.1807326361331434&41.38680260504134,2.188132850805232&41.38458293055814,2.1758925899657697&destination=41.38394800519846,2.166872321048686&sensor=true&mode=walking
Is the above format right for passing multiple way points?
The main issue I am facing is that the route is not going through all the way points I am passing.
I am always getting a "waypoint_order" : [ 0 ].

use '%7C' instead of '&' in your waypoint request. i.e.
https://maps.googleapis.com/maps/api/directions/json?origin=41.3758887,2.1745799999999917&waypoints=41.39097711845494,2.1807326361331434%7C41.38680260504134,2.188132850805232%7C41.38458293055814,2.1758925899657697&destination=41.38394800519846,2.166872321048686&sensor=true&mode=walking

Related

How to pass custom coordinates to map box navigation launcher?

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.

Avoid specific point in android map

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.

Can alternate routes be set up with different viapoints?

I am trying to create 3 alternate routes, as in the demo project. After the routes are calculated, I would like to insert different SKViaPoints along each route. Is this possible? SKViaPoint only seems editable at the SKRouteManager level, which would give all alternate routes the same via points.
Thanks in advance.
This is not supported - the alternative routes will use the same start, destination and via points as the original route. You can change the routing constraints used for alternatives but not the start/end/viaPoints.
If you need to calculate multiple routes with different settings, call the calculate route API with "setRouteExposed" to false

Finding the shortest route from current location to the locations marked on a map

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.

Quadtree on android maps utils

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.

Categories

Resources