Hi all,
I am trying to get the JSON output of directions between two points
using the Directions API Web services. I am using an XmlHttpRequest
(GET Method) in Javascript to get the results but gives me an error
"XMLHttpRequest cannot load
http://maps.googleapis.com/maps/api/directions/json?origin=43.0480556....
Origin http://localhost:51724 is not allowed by Access-Control-Allow-
Origin."
Not from the client, because the browser stops it happening. The
Javascript specification prevents cross-domain access with
XMLHttpRequest. If you're using directions client-side, you should use
the client-side tools provided.
The standard workaround for cross-domain requests is to implement a
proxy on your own domain.
Note: even though you have used Access-Control-Allow-Origin, it is set
on *your* server, not Google's, only IE8/9 will recognise it; and it
requires XDomainRequest, not XMLHttpRequest. Google's servers may
respond to XDomainRequests from arbitrary clients, but you can't force
that.
http://msdn.microsoft.com/en-us/library/dd573303%28v=vs.85%29.aspx
Doesn't look like it. Even if it works, it couldn't be relied upon
because it's not documented.
http://code.google.com/apis/maps/documentation/directions/#RequestParameters
May take more time to load than what?
Basically, you have two choices: either use the client tools, or
implement a proxy (which will come with its own hazards, like using
the server's ip address).