how to write a directions request for Google Maps Directions? - android

I am making an android app that uses the google maps directions services. I have finished almost all of the app but i have a problem with the directions request. I need that the request will give me a bus route and that there will be no transfers. I know i need to use the transit_mode bus ,and the transit_routing_preference fewer_transfers. but i dont know how to add it to the request. do i need to write &transit_mode=bus&transit_routing_preference=fewer_transfers& ?
i looked everywhere but i still dont know how to add those options to the request.

The Google Maps Directions API uses a simple HTTP interface, you're on the right track setting the transit_mode=bus and transit_routing_preference=fewer_transfers. You'll also need to set mode=transit to activate transit mode.
I think the final URL you're looking for will look like:
https://maps.googleapis.com/maps/api/directions/json?origin=Mountain%20View&destination=1600%20Amphitheatre%20Parkway&mode=transit&transit_mode=bus&transit_routing_preference=fewer_transfers&key=YOUR_API_KEY.
Note - The transit_mode and transit_routing_preference parameters will bias your results, but not guarantee the results will always be a bus route with 0 transfers. You'll need to design your application to handle > 0 transfer bus routes.

Related

How can I control my direction type preference in the new Google Maps link URLs?

I would like to be able to have a Google Maps direction link which, when opened on mobile (Android), would bring up directions in Google Maps using a specified direction type (e.g. bicycle).
Using the old Google Maps URL parameters you can do,
https://www.google.com/maps/preview?saddr=[insert_from_address_here]&daddr=[insert_to_address_here]&dirflg=[insert_mode_here]
but it doesn't work on mobile.
Using the new Google Maps URL parameters you can do,
https://www.google.com/maps/dir/[customer address]/[our address]/am=t/
which does work on mobile but I don't know how to specify direction type.
From the Google Forum itself, try this on your URL if this works.
Car /data=!4m2!4m1!3e0
Bicycling /data=!4m2!4m1!3e1
Walking /data=!4m2!4m1!3e2
Public Transit /data=!4m2!4m1!3e3
Airplane /data=!4m2!4m1!3e4
For example
https://www.google.com/maps/dir/747+Howard+St,+San+Francisco,+CA/55+Music+Concourse+Dr,+San+Francisco,+CA/data=!4m2!4m1!3e3
For more information, juct check the link above and this stackexchange question.

How can I open Google maps in walking mode

How can I start Google Maps at walking mode to a destination? I know how to open in navigation mode. I have not found a way to open it in plain walking mode
You have to add the mode parameter as part of your Directions request. mode is one of the optional request parameters that specifies the mode of transport to use when calculating directions. If no mode is specified, the Google Maps Embed API will show one or more of the most relevant modes for the specified route.
Below is a sample Direction request that returns walking directions from Indianapolis to Chicago. If the parameter &mode=walking was removed, the request will return the directions with most relevant modes instead.
https://www.google.com/maps/embed/v1/directions?key=[YOUR API KEY]&origin=indianapolis&destination=chicago&avoid=tolls|highways&mode=walking
Reference:
https://developers.google.com/maps/documentation/embed/guide
It is really just a case of pushing directions instead of start right after you set the address. Directions gives you a chance to change the vehicle. If you go directly to start you won’t see that option.

How to get Ola Cabs Api key?

I need to implement Ola cabs Api in an android app. I am following this link - http://docs.console.olacabs.com/ola.
But everytime I try and fetch some data, it says "Authorization Error". I need a valid Api key to use the services but can't find a way or link to generate one.
try #ndo1d
http://blog.attify.com/2015/02/01/ola-cabs-privacy-security-issue-discovered-appwatch/
https://medium.com/#CodeTheDevil/busting-ola-wallet-1ceea6174b1f
You can use the application normally, and AppWatch will show you the real time application’s network traffic. AppWatch is an intelligent platform, with which it automatically identifies APIs which could be vulnerable. As soon the app does something which AppWatch identifies to be vulnerable, it simply displays a vulnerable tag along with the request.
Usually you have to insert an API Key in the header of the request to access API's functions.
I don't know exactly if it's the case, or if you have generated the API Key, if this key has authorization to access the resource you want.
Please check: Do you have an API Key? Does it provide access to what resources?
ps: I can't comment. That's why I wrote an answer.
Register here to get API Key..
https://developers.olacabs.com/docs/ride-availablity

Is there an Android equivalent to Google Maps URL scheme for iOS?

I want to open Google Maps in Navigation mode from a mobile web link. This seems easy enough for iOS devices using https://developers.google.com/maps/documentation/ios/urlscheme
Is there an equivalent for Android? All I could find was this: https://developer.android.com/guide/appendix/g-app-intents.html
But that doesn't allow you to specify "transitmode" and the other parameters needed to get directions as far as I can tell.
Actually, a slight modification of the methods described in the iOS Doc would work here too (I tested it before putting it here albeit, in a native app and not a web link).
The parameters necessary for this to work are pretty much the same as with the ones listed in the iOS documentation:
From the iOS Docs:
Parameters:
saddr: Sets the starting point for directions searches. This can be a
latitude,longitude or a query formatted address. If it is a query
string that returns more than one result, the first result will be
selected. If the value is left blank, then the user’s current
location will be used.
daddr: Sets the end point for directions searches. Has the same
format and behavior as saddr.
directionsmode: Method of transportation. Can be set to:
driving, transit, or walking.
They are actually, pretty much the same. They are however, no where to be found in the documents. Also, while the first 2 parameters work the usual way here, the last parameter directionsmode does not work as is. A workaround is however, listed below.
That being said, a simple URL can be constructed that can then be passed as an Uri to an Intent that will then handle the application to be launched (Google Maps if installed and/or list of browsers to choose from)
String mapURL = http://maps.google.com/maps?saddr=-33.9417, 150.9473&daddr=-33.92050, 151.04287&dirflg=d
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(mapURL));
startActivity(intent);
A few variations for the Transit Mode:
&dirflg=d = for Driving directions (this is the default mode. leaving it out is the same as putting it in explicityly).
&dirflg=w = for Walking directions
&dirflg=r = for Public transit.
&dirflg=b = for Biking directions.
That being said, at the time of running these test (I admit I was curious enough to test a little further after seeing this question ;-) ), the modes listed in the Travel Modes section don't seem work!
A little proof of sorts:
Note: Credit for the initial discovery of the options

Google Map APIs : UK specific results

I'm developing a map application in Android. I'm using Google maps API to show results in Autocomplete textview dropdown .The results this API is returning is of the places of the entire world . I want to show results o provide solutions to places only of a particular country eg .UK
How should I do it . Is there any specific flag to be set for it .
My URL :
private static String SUGGETION_URL = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%s&types=geocode&sensor=true&key=xxxxx.xxx-xxxxx";
Please suggest ways by which this url will return results to places only in UK ?
There's no way to force the API to restrict it's results to a region like you can in some of the other Google Maps Web Service APIs. If you really need that functionality then maybe you should be using the Geocoding API or the Places Autocomplete API as included in the Google Maps JS V3 API.
If you can't use either of those two suggestions your options are limited to:
You can use the location / radius parameters like you found, but there are treated as more like "suggestions" than absolutes.
I'd try setting the language parameter to en-GB which might favor UK-based results slightly over others.

Categories

Resources