Driving Directions JSON Response

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Driving Directions JSON Response

Postby Paranoid » Wed Mar 04, 2009 4:23 pm

Hi,

I was wondering what the URL syntax is to recieve a JSON response of driving directions?

I'm guessing it must start

http://maps.google.com/maps/nav?&key=

but I'm not sure what comes after this, everything I have tried brings back a response code 400.

Thanks

P.
Paranoid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Oct 19, 2008 5:10 pm

Top

Postby atxe » Thu Mar 05, 2009 9:29 am

In HTTP protocol, the response code 400 means "Bad Request".

I suggest you to try that:
http://maps.google.com/maps?q=from%3A<HERE_1>to%3A<HERE_2>&key=<API_KEY>&output=kml&sensor=true&oe=utf8

Where:
<HERE_x>: Addresses > if you need to put spaces put "+"
<API_KEY>: Your api key
If you want JSON you can remove the output parameter. Anyway I recommend you parsing KML, it's easier and more efficient (in terms of memory usage and processing).

If you only need the location of one address simply don't use "from" & "to" ;-)
atxe
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Feb 27, 2009 12:12 pm

Postby Paranoid » Thu Mar 05, 2009 10:28 am

Cheers atxe, works a treat.

However i'm now trying to join these points that I receive by drawing a line connecting them on the map.

The problem here is that any line that I draw on the map goes directly from point A to point B, without actually taking the route of the roads into consideration.

Anything I've seen that allows this is no longer possible in the 1.0 SDK, so any ideas on whether this is infact possible in the 1.0 SDK?

Thanks again

P.
Paranoid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Oct 19, 2008 5:10 pm

Postby atxe » Thu Mar 05, 2009 10:47 am

Thx.

Yep, that's what I'm doing right now in my project. In older versions of the SDK (I guess in version 0.9) you could directly interact with navigation libraries. Now this library is not available so you have to think in alternatives to do it. These are the possible ideas I have thought in:
http://www.anddev.org/alternatives_to_c ... t5021.html

In order to draw the route, I have taken the decision of parsing the KML file, it's a standard (developed by google) for coding maps in a format in XML way. In KML you'll find the tag <GeometryCollection> where is the coordinates required to draw the path.

I guess I'll release my code in a few months when my thesis is completed.
atxe
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Feb 27, 2009 12:12 pm

Postby Paranoid » Thu Mar 05, 2009 1:00 pm

Ah ok

So basically you're taking the list of coordinates from <GeometryCollection> and doing something like

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. path.lineTo(lat, lng);
  3.  
  4.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


for each one to create a path?

I'm not sure if this will work as I havn't really used the Path class before.

Is this what you are doing yourself?
Paranoid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Oct 19, 2008 5:10 pm

Postby atxe » Thu Mar 05, 2009 2:19 pm

Emmm, maybe it can be done in the way you said. Neither have I used the Path class before :Q

I'm using canvas.drawLine method to draw strokes for each pair of GeoPoints parsed from <GeometryCollection>.
atxe
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Feb 27, 2009 12:12 pm

Top

Postby Paranoid » Thu Mar 05, 2009 2:39 pm

Yeah your way is probably best, I'm not even sure using Path will give a straight line as I think it will try an join the start and end points together to give some sort of shape.

So thanks again for your help, I probably would have been stuck indefinately otherwise :D

Oh and one more thing, is the use of sending the http request and parsing the response a no-no in regards to Google's terms and conditions?

*edit* excuse my lazyness in not reading the terms and conditions, just thought it would be quicker to ask.
Paranoid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Oct 19, 2008 5:10 pm

Postby atxe » Thu Mar 05, 2009 2:47 pm

You are welcome.

Maybe, I think that drawline is a "basic method" so I hope it's one of the most efficient ways to draw it :D

As I understood these terms and conditions, you're allowed to use it if you're drawing it in a map.
atxe
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Feb 27, 2009 12:12 pm

Postby zpk1234 » Sat Jun 27, 2009 2:28 pm

atxe wrote:In HTTP protocol, the response code 400 means "Bad Request".

I suggest you to try that:
http://maps.google.com/maps?q=from%3A<HERE_1>to%3A<HERE_2>&key=<API_KEY>&output=kml&sensor=true&oe=utf8

Where:
<HERE_x>: Addresses > if you need to put spaces put "+"
<API_KEY>: Your api key
If you want JSON you can remove the output parameter. Anyway I recommend you parsing KML, it's easier and more efficient (in terms of memory usage and processing).

If you only need the location of one address simply don't use "from" & "to" ;-)


I am try to do that, but why I received an empty kml file?
I input this is browser:
http://maps.google.com/maps?q=from%3Ali ... ue&oe=utf8
zpk1234
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jun 27, 2009 1:17 pm

Postby atxe » Sat Jun 27, 2009 2:57 pm

zpk1234 wrote:
atxe wrote:In HTTP protocol, the response code 400 means "Bad Request".

I suggest you to try that:
http://maps.google.com/maps?q=from%3A<HERE_1>to%3A<HERE_2>&key=<API_KEY>&output=kml&sensor=true&oe=utf8

Where:
<HERE_x>: Addresses if you need to put spaces put "+"
<API_KEY>: Your api key
If you want JSON you can remove the output parameter. Anyway I recommend you parsing KML, it's easier and more efficient (in terms of memory usage and processing).

If you only need the location of one address simply don't use "from" & "to" ;-)


I am try to do that, but why I received an empty kml file?
I input this is browser:
http://maps.google.com/maps?q=from%3Ali ... ue&oe=utf8


A +to was missing!

And the "formula" was missing a "+" so it is in the following way:
Code: Select all
http://maps.google.com/maps?q=from%3A<HERE_1>+to%3A<HERE_2>&key=<API_KEY>&output=kml&sensor=true&oe=utf8

<HERE_x>: Addresses > if you need to put spaces put "+"
<API_KEY>: Your api key
If you want JSON you can remove the output parameter. Anyway I recommend you parsing KML, it's easier and more efficient (in terms of memory usage and processing).


Try this:
http://maps.google.com/maps?q=from%3ABa ... ue&oe=utf8

And now, in KML output format:
http://maps.google.com/maps?q=from%3ABa ... ue&oe=utf8
atxe
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Feb 27, 2009 12:12 pm

Postby zpk1234 » Sat Jun 27, 2009 3:28 pm

thank atxe for soon reply,
Next I will prase this kml file!
my english is poor! :)
zpk1234
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jun 27, 2009 1:17 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests