How can we reduce Google Maps api calls??
in one of our app (similar like uber) we are using Google directions api to plot two points(source and destination) and dynamic path between them,
so we have to update this path every-time in 4-5 seconds ,
In 2 months mostly 1.2 million requests are getting generated for directions api , and google maps charging almost $5k-8k per month which is very high. Any mechanism to optimise the same.
Don't make the call every 4-5 seconds. Why are you doing that anyway? The location doesn't change that much in 4-5 seconds, it may not change at all (they may be stuck at a light). Instead, track their GPS location and update it only every few hundred meters. That's a good step one. A next step after that would be to look at the actual route data returned by the API, and use the GPS data to see if the user is following the route, and update only if the user significantly deviates from it. This is also how Maps and GPS devices work- you'll notice that deviating from a route takes some time for the device to notice, and then it recalculates.
To do the latter- the DirectionsResult object holds a set of legs. Each leg is the directions to a single waypoint (so if you're just going directly to one place, it will be a single leg). Inside that is a series of steps. Each step has start and end GPS coordinates. If you're moving in the general direction from start to end GPS coordinates, no need to recompute. Unless your route is extremely curved, this would be good enough. There's also paths within a step that provides a series of points along the step, you can probably use that if it exists to provide more exact navigation along complex steps.
Related
I have a service, from which I get the user's location on an interval of time (e.g. 7 seconds). The walking path is displayed on the map, but as you can see there're many invalid locations, since the GPS receiver is trying to obtain the exact current position.
The blue one is the displayed walking path and the black one is the actual walked. I was thinking of using the IMU as kind of a filter in order to check whether the retrieved location is on the path, or the location provider needs more time to update it.
Is it possible doing it in this way?
Yes in theory its possible to improve the GPS position with an IMU, but it requires a Kalman-Filter, which is not trivial to set up correctly and get it working correctly on range of devices. There lots of resources on the internet explaining how a Kalman-Filter works and what it can be used for.
I also recommend reading this blog post: https://blog.maddevs.io/reduce-gps-data-error-on-android-with-kalman-filter-and-accelerometer-43594faed19c . The authors pretty much wanted to achieve the same thing as you by using a Kalman-Filter. They also published a library on github for a Kalman-based location estimation.
We are startup company in transport section.
We are getting a lot of charges for this like 400$ and above per day with consistent increase of users in the app .
1.We are using google map api and hitting every 2 second for smooth vehicle movement because if we increase the time limit than the problem is vehicle movement is jerking and jumping . we want smooth movement in an optimized way so as to reduce the cost .
Please suggest your opinion . Thanks in Advance
You must have to make a system to store or caching the data you get from google map api. You can use Mapbox to get the alternative solution. MapBox gives you 50000 free request per month per every api. I faced the same problem. I use both Google map api and Mapbox api and also cache the data to reuse.
For smooth vehicle animation you can follow this link: https://github.com/amanjeetsingh150/UberCarAnimation
Vehicle movement can be done offline. No need to pay for it.
And also, if you think, you can have a look at MapBox: http://mapbox.com/
On our website we we plot two points on a map, and the google direction api neatly gives us the traveling time. If we change the from or to address some new calculation are performed, and the new traveling time is displayed on the site.
We are trying to create the same kind of setup in Android, but I see that there is no support for the directions API. I have looked at some old examples like this one Drawing a line/path on Google Maps but here there is just a simple line between two points. I do not see anything about the traveling times.
Another question I stumbled uppon was the following Directions API on Android but I do not see how the connection is made between the Android Maps API and the Google maps direction API.
To draw path you can use this library
Through this library you can get travel duration between two point. now when you move to your destination location you have to calculate your speed and remaining destination distance. from your speed you can assume you destination reach time.
To calculate your moving speed this link will help you
I'm developing an application which requires the user's path taken to be recorded, and measured. I'm already familiar with utilizing onLocationChanged to receive location change updates, but how could I use these Location points to create a complete path, encompassing their entire trip from one location to another?
I was thinking I could utilize each Location passed as a point, and simply connect all of the points with a polyline, but this seems to me like it would be a weird and slightly ugly line (as location approximations aren't always super-accurate).
Another idea I had would be to acquire each street the user travels down, and then ultimately connect them all, but I'm not even certain as to how I would perform this.
Any ideas?
The best method would be to have some kind of representation of the map,
then keeping your recent locations in a data structure (omitting too close locations by keeping only locations in fixed deltas, for example).
Then you could match the points to nearest roads, and calculate their projection on them to created a matched path on the map.
Since I've implemented this before, I can tell that it involves quite a bit of work, having some representation of the map as a graph (say using OSM), and knowledge with geometric queries (in PL/PGSQL probably if we talk about OSM).
The trigonometric calculation themselves are rather easy and can be found on the web (E.g. projection of point on a given line).
To get quality results, you'll also have to deal with your progress along the route (I.e. filtering gps points that lead you "backwards" instead of "forward" by mistake due to GPS signal error).
You'd better off starting with a working POC:
Depending on your map implementation (Google / OSM)-
Choose some kind of an online routing provider (http://wiki.openstreetmap.org/wiki/Routing/online_routers).
Then you could send small navigation requests between locations you stored earlier. Since their delta is small, you'll probably get the relevant matched path on the road.
Downsides: You depend on an external service and its quota, and can't serve many clients without paying.
Advantages: You could build a working POC in a small amount of time (~hours)
Either way, you'll be bound to the quality of your given map (e.g. updated roads, turn restrictions) that will determine the correctness of your results.
i am developing an android application that use map view.
i can add point to the map, zoom, get current location and animate to point.
but how to get direction between 2 points?
when user click on point to show direction between current location and clicked location.
Thanks
but how to get direction between 2 points?
Math. This has nothing to do with Android. It has little to do with maps, even. It has everything to do with math.
Depending on the distances involved, you might be able to get away with treating things as plain Carteisan coordinates and do the necessary trigonometry. Over a significant distance, though, the curvature of the Earth starts to play a role, and the math will get harder.
You might consider using a search engine to find whatever versions of the formulas you would like to use.
in order to show a direction on maps (android)
you can try to make an Overlaying custom route on your application.
We shall further assume that the route returned may contain additional information such as the local slope of the route (which could be important if one is negotiating the route in a wheelchair, for example). Since this requires a network access that could block the main UI thread if there are network difficulties, we shall also use this example to introduce the important skill of putting time-consuming or potential UI-blocking tasks on a background thread. and use AsyncTask to run the process in the background. To use AsyncTask we must subclass it.
maybe this is helped you out.