How to specify an address in a Google Maps Directions API URL - google-maps

How do you specify an address in a Google Maps Web Services Directions API URL? The Maps Web Services page states
Converting a URL that you receive from user input is sometimes tricky. For example, a user may enter an address as "5th&Main St." Generally, you should construct your URL from its parts, treating any user input as literal characters.
However this isn't very clear. There are no examples and I haven't been able to find any on the web. Does this mean that, for the given example, "5th&Main St." the following valid?
https://maps.googleapis.com/maps/api/directions/json?destination=5th%26Main+St.&sensor=true
If not, what would be the correct conversion?
Thanks for reading.

As per my understanding, you are looking for URI encode.
In Javascript:
encodeURI is used to encode a string with special characters including
foreign language.
Example:
var address = "5th&Main St.";
var encodedAddress = encodeURI(address);
then pass the encodedAddress in the google maps API.
https://maps.googleapis.com/maps/api/directions/json?destination=encodedAddress&sensor=true
A small list of symbol equivalent encoding (Percent encoding):
space %20
! %21
" %22
# %23
$ %24
% %25
& %26 // this what happended in your case
' %27
( %28
) %29
Once I faced an issue, whild doing geocoding via C#.
Where I did a similar URI encoding using HttpUtility.UrlEncode() for address and then passed it to the Google API as I mentioned in above. Each language has its own encoding technique, yet the output is same.
Hope you understand.

Related

in SAS: create a JSON Web Signature for Google API

I am using SAS 9.4. I want to write a JSON Web Signature ("JWS") to complete my JSON Web Token ("JWT") - (I already have the header and claims encoded and tested). I would like to make API calls to Google. My problem is that I am not certain how to create the JWS. Per all the docs and tutorial web sites I have researched the syntax to create the signature is (pseudo-code):
encodedContent = base64UrlEncode(header) + "." + base64UrlEncode(payload);
signature = hashHmacSHA256($encodedContent);
and/or
var encodedString = base64UrlEncode(header) + "." + base64UrlEncode(payload);
HMACSHA256(encodedString, 'secret');
etc.
I have been attempting to create the JWS using SAS PROC GROOVY code found here:
https://gist.github.com/FriedEgg/79ad315afa1b315e8ac3
...and other places.
Google's doc (https://developers.google.com/identity/protocols/OAuth2ServiceAccount) states:
"Sign the UTF-8 representation of the input ('{Base64url encoded header}.{Base64url encoded claim set}') using SHA256withRSA (also known as RSASSA-PKCS1-V1_5-SIGN with the SHA-256 hash function) with the private key obtained from the Google Developers Console. The output will be a byte array."
However, I am confused about what key to use (or whether I should be using a key) as some sites (example above) just suggest hashing the encoded header+claims while others suggest hashing using a "secret key" while say "private key" - and the github page (URL above) just uses a "key".
I am also confused about sha1 vs. sha256. The Google docs sate sha256 but some have suggested sha1 in this Stack Overflow thread: questions/18362327/creating-digital-signature-usining-sas-for-google-api-geocode
Again, I have verified my header and claims SAS code work using:
jwt dot io
and
kjur dot github dot io/jsjws /tool_jwt.html
Since SAS supports Groovy (PROC GROOVY) I assume that I can write my JWT successfully using java code but I have not yet been able to replicate any JWT in my SAS code using examples found on the sites I have mentioned above and others.
Has anyone ever done this before (using SAS to connect to Google APIs using JWT)?
Any help is appreciated!

What does the # mean in URLs?

I noticed in webpages such as Google maps there is an # in the URL. What does it do? For example https://www.google.com/maps/place/Vancouver+City+Hall/#49.260404,-123.113799,3a,75y,349.48h,90t/data=!3m4!1e1!3m2!1sUeoHwwwaQPVvyH1amrQAAQ!2e0!4m9!1m6!2m5!1sgoogle+maps+vancouver+city+hall!3m3!1scity+hall!2sVancouver,+BC,+Canada!3s0x548673f143a94fb3:0xbb9196ea9b81f38b!3m1!1s0x548673e7b8d4609d:0x9823432c0c571e10!6m1!1e1
An URL in general is not consistenly consisting of directories followed by a file. Before it eventually beeing a physical directory+path, it's just a string, not more, not less. There is only 1 real special character in URL that is not part of this URI string: # (Hash fragment identifier).
Basically you can map any string after //yourdomain.com/ (and before #) to anything you want.
Therefore, the # character in the URL only has cosmetical/optical/ however you call it meaning.
The ? and & have a special meaning in terms of, the server can use these symbols to identify parameters. But it does not have to do so. It is in fact possible to map an URI like //yourdomain.com/&&& to a complete different resource than //yourdomain.com/&&.

Google maps directions service

I have an issue whith google maps directions service (api v3). I don't know how specify the origin and destination strings. For example for the requests:
http://maps.googleapis.com/maps/api/js?sensor=false&region=ES&languaje=es&key=xxxxxxxxxxxxx&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010"
or
http://maps.googleapis.com/maps/api/directions/xml?sensor=false&region=ES&languaje=es&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010"
the response of the server is: NOT_FOUND, ie route not found,
however if I change the character Ñ by N, ie ESPAÑA by ESPANA the response is OK.
There are other places with "especial characters" for example: Göttingen, München, Köln, ....
I have been looking for information in the documentation but can not find anything about.
How can I specify the different origins and destinations?
Regards,
Francisco
Request http://maps.googleapis.com/maps/api/directions/xml?sensor=false&region=ES&languaje=es&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010" is true, you can test it in browser.
If you have issue in request maybe it come from URL Encoding. With special character in string URL you need encode it before do request with this string

How to stop percent encoding in HTML form submission

I am trying to give users of my website the ability to download files from Amazon S3. The URLs are digitally signed by my AWS private key on my webserver than sent to the client via AJAX and embedded in the action attribute of an html form.
The problem arises when the form is submitted. The action attribute of the form contains a url that has a digital signature. This signature often times contains + symbols which get percent-encoded. It completely invalidates the signature. How can I keep forms from percent-encoding my urls?
I (respectfully) suggest that you need to more carefully identify the precise nature of the problem, where in the process flow it breaks down, and identify precisely what it is that you actually need to fix. URLEncoding of "+" is the correct thing for the browser to do, because the literal "+" in a query string is correctly interpreted by the server as " " (space).
Your question prompted me to review code I've written that generates signed urls for S3 and my recollection was correct -- I'm changing '+' to %2B, '=' to %3D, and '/' to %2F in the signature... so that is not invalid. This is assuming we are talking about the same thing, such that the "digital signature" you mention in the question is the signature discussed here:
http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationQueryStringAuth
Note the signature in the example has a urlencoded '+' in it: Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D
I will speculate that the problem you are having might not be '+' → '%2B' (which should be not only valid, but required)... but perhaps it's a double-encoding, such that you are, at some point, double-encoding it so that '+' → '%2B' → '%252B' ... with the percent sign being encoded as a literal, which would break the signature.

How to get Google Maps Public Transit Directions by HTTP server-side request

I use such urls like:
http://maps.google.com/?saddr=546%206th%20Avenue,%20New%20York,%20NY%2010011%20(Sixth%20Avenue,%20New%20York)&daddr=W%20103rd%20St,%20New%20York,%20NY%20&dirflg=r
But it returns full html page. Does anybody know how to get such info in json or xml or any parsable format?
I need public transit.
You just add &output=json to the end of the url.
I'd like to extend Mathias's answer a little bit.
There's no official Google Transit API at the momemnt. Transits are provided by agencies, and most of Transits are not public. So, Google is not allowed to open them as API.
You may try to consume the "unofficial" data using your link + "&output=json".
However, the result won't be a valid JSON. Instead, that's something, that can be easily converted to a JavaScript object. (The differences are: there is no quotes around property names,
the strings are not properly encoded etc.)
Imagine you got this JavaScript object. However, it won't allow you to easily get the structured route details. Object's properties contain the route points coordinates, but no descriptions. The only place where the descriptions may be found is 'panel' property, which contains a chunk of HTML text (you may find a link to the sample of HTML in my blog post)
So, you'll have to convert this HTML into XML (X-HTML) and then build the parser of this XML to get the essence data of a trip.
Seems like a bit of overkill to me. Having in mind, that "unofficial" API may change in the future, including slight changes in 'panel' HTML structure that will kill your parser.
#MathiasLin, how did you overcome this?
Google Maps Javascript v3 and the Directions Web Service now has this capability as per :
https://googlegeodevelopers.blogspot.in/2012/06/public-transit-routing-and-layer-now.html
Update:
Latest server side API docs:
https://developers.google.com/maps/documentation/directions/get-directions
Re choosing public transport - it seems that it defaults to public transport now (at least when I use it).
Changing the last URL parameter, dirflg=r, into dirflg=w switches the directions to walking mode.
Plus see:
Walking, bicycle and public transport directions with time required in each mode , iPhone
for more detail about the parameters.
Google direction API response is in HTML, JSON format please check https://developers.google.com/maps/documentation/javascript/directions?hl=lv
& section 'The DirectionsResult Object'