I am trying to use google maps directions API with continuous hitting to the API and updating the directions by getting a current location on location changed listener and it works perfectly.
But Instead of hitting multiple times I need to get directions API for the single instance and write an algorithm by getting the directions using segments start point and update on google map, Find a way to know the user is traveling in the wrong distance and re-route map by calling API.I tried these ways and working but there are a lot of cases to be handled for these scenarios.
I don't understand what to follow and why this is required is, we have a display cycle and the user starts the navigation and directions should be shown on cycle hardware display via BLE.
Please help me solving this issue.
You can try using the Google Maps Util Library. The PolyUtils class has methods to check if a LatLng lies on a polygon/polyline.
Maybe try using the method isLocationOnPath. And if it's outside the polyline, make the request to directions API and re-plot the route.
Docs: http://googlemaps.github.io/android-maps-utils/javadoc/
Related
Is there a simple way to achieve showing the output from DirectionServices onto a Google Map? The closest I could find was this answer -- How to draw road directions between two geocodes in android google map v2?
But that needs a bit of modification...
I'm ok with either Google API or 3rd party libraries too
Thanks,
Ram
Given in Google Maps JavaScript API - Displaying the DirectionsResult, you may opt to handle yourself the DirectionsResult which contains the result of the directions of the query or you can choose to automatically handle displaying the result on a map by passing a DirectionsRenderer object.
To display a DirectionsResult using a DirectionsRenderer, you simply need to do the following:
Create a DirectionsRenderer object.
Call setMap() on the renderer to bind it to the passed map.
Call setDirections() on the renderer, passing it the DirectionsResult. Because the renderer is an MVCObject, it will automatically detect any changes to its properties and update the map when its associated directions have changed.
A DirectionsRenderer not only handles display of the polyline and any associated markers, but also can handle the textual display of directions as a series of steps. To do so, simply call setPanel() on your DirectionsRenderer, passing it the <div> in which to display this information.
More information and examples to fully understand Google Maps JavaScript API - Directions Service can be obtained from the documentation.
i'm getting latitude and longitude of a location, I want to know the roads connecting to that location and whether it is land or water
I tried one google map api which is not helping to get the information i want.
http://maps.google.com/maps/api/geocode/json?latlng=40.7127,74.0059&sensor=true
Another SO answer pointed out two possible workarounds:
You can use Google Maps Reverse Geocoding . In result set you can determine whether it is water by checking types. In waters case the type is natural_feature. See more at this link http://code.google.com/apis/maps/documentation/geocoding/#Types.
You can detect waters/lands by pixels, by using Google Static Maps. But for this purpose you need to create http service.
You can use the Google Maps Geocoding API which does exactly that: http://code.google.com/intl/da-DK/apis/maps/documentation/geocoding Take a look at the "Reverse Geocoding" section
In javascript, using Google maps apis we specify options such as google.maps.TravelMode.DRIVING. Do we have any equivalent for TravelMode in android? I couldn't see anything in android.location.LocationManager or android.location.Criteria
I've thought of following options:
Using some TravelMode alternative, get coordinates approximated to nearest street/road.
Alternatively, (Not preferred as it will be slow) get the coordinates normally and then probably send it to some google api(This will be pretty slow as there are many points) and get the coordinates corrected to the nearest street coordinates. Or in case if there exists some (google-maps) javascript framework, it may be used to get corresponding street coordinates.
Edit1:
I've also looked into this. and hence into android.location.Geocoder. The getFromLocation in this class seems to do most of the work. However, I'm afraid, of an additional delay while acquiring the nearest address.
If you are referring to Directions Service, then it uses Google Directions API internally as stated in the overview:
This object communicates with the Google Maps API Directions Service which receives direction requests and returns computed results.
As there is no native API for Android yet, I suggest using Directions API directly.
See my answer here.
I have been trying to figure out driving directions using user input and it looks like that functionality has been removed from the google maps API. Is this corrects? I have been searching and have not been able to find any documentation on how to get directions using user input. Does anyone know of any tutorials or documentation on this?
The official documentation contains everything you need:
make a request to retrieve the coordinates related to the user-input: Geocoder.geocode()
Fetch the latlng out of the GeocoderResult
Request the route by using DirectionsService.route() and the given start/endpoint
set the route by using DirectionsRenderer.setDirections()
I would like to start a Maps activity and get back a location result. Is this doable without using a MapView and having to require the google maps library?
Yes it is possible.
you should add "onclick" event listener to your map. It will return coords when event is fired.
Please find more details in map API documentation. http://code.google.com/apis/maps/documentation/javascript/events.html
You know the Geo position / name of the location. You can get the location information using Google Maps Web Service API.
Pleas look into the following link for details. http://code.google.com/apis/maps/documentation/webservices/
If you are sure about getting location information from Map Acitivity, You cant achieve it without using MapView.
PS: Other Suggestion is You can have it a static map and respective location matrix if the map area is well defined.