Compute route between 2 locations

Dec 27, 2008 at 5:44 PM

Hi radioman,

I tried to use the control in my app and are very content with. It would be outstanding, if we could compute the route between 2 locations and show this on the map. Would that be possible?

greetings

Erich

Coordinator
Dec 29, 2008 at 1:09 PM
Hey, I'll definitely try to investigate that ;}
Coordinator
Jan 7, 2009 at 5:43 AM
Edited Jan 7, 2009 at 7:39 AM

investigation done, this gives us coordinate list of route:

*geocoding:   http://maps.google.com/maps?f=q&output=kml&doflg=p&hl=lt&q=&saddr=klaipeda&daddr=vilnius

*coordinates: http://maps.google.com/maps?f=q&output=kml&doflg=p&hl=lt&q=&saddr=@54.7233,25.24287&daddr=@54.702011,25.288124

start -> &saddr

end-> &daddr

//-----------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8" ?> 
- <kml xmlns="http://earth.google.com/kml/2.0">
- <Document>
<name>Ukmergės gatvė į Trimitų gatvė</name> 
- <Style id="roadStyle">
- <LineStyle>
<color>7fcf0064</color> 
<width>6</width> 
</LineStyle>
</Style>
- <Snippet>
- <![CDATA[ <font size=+1><a href="http://maps.google.com/maps?f=q&doflg=p&hl=lt&q=&saddr=@54.7233,25.242870000000003&daddr=@54.702011,25.288124">Spausdinamas vaizdas</a></font>
]]> 
</Snippet>
- <Placemark>
- <description>
- <![CDATA[ eiti 5,9&#160;km
]]> 
</description>
<address>Ukmerges gatve</address> 
<styleUrl>root://styleMaps#default+nicon=0x406+hicon=0x416</styleUrl> 
- <Point>
<coordinates>25.242870,54.723300,0</coordinates> 
</Point>
- <LookAt>
<longitude>25.242870</longitude> 
<latitude>54.723300</latitude> 
<range>100.000000</range> 
<tilt>45.000000</tilt> 
<heading>162.044556</heading> 
</LookAt>
</Placemark>
- <Placemark>
<name>Atvyksta: Trimitų gatvė</name> 
<address>Trimitu gatve</address> 
<styleUrl>root://styleMaps#default+nicon=0x467+hicon=0x477</styleUrl> 
- <Point>
<coordinates>25.288124,54.702510,0</coordinates> 
</Point>
</Placemark>
- <Placemark>
<name>Maršrutas</name> 
- <description>
- <![CDATA[ Atstumas: 5,9&#160;km (apie 9 minutės)<br/>Žemėlapio duomenys &#169;2009 Tele Atlas
]]> 
</description>
- <GeometryCollection>

- <LineString>
<coordinates>25.242870,54.723300,0.000000 25.244110,54.721090,0.000000 25.245720,54.718430,0.000000 25.246230,54.717260,0.000000 25.246710,54.716350,0.000000 25.248480,54.713440,0.000000 25.249800,54.711600,0.000000 25.250470,54.710850,0.000000 25.252230,54.709100,0.000000 25.253210,54.708020,0.000000 25.257630,54.703660,0.000000 25.257970,54.703380,0.000000 25.258520,54.703070,0.000000 25.259150,54.702830,0.000000 25.261760,54.702140,0.000000 25.261930,54.702070,0.000000 25.262340,54.701840,0.000000 25.262870,54.701360,0.000000 25.263220,54.700560,0.000000 25.263080,54.700220,0.000000 25.263000,54.699280,0.000000 25.262810,54.698910,0.000000 25.262630,54.698730,0.000000 25.262560,54.698590,0.000000 25.262560,54.698460,0.000000 25.262600,54.698300,0.000000 25.262760,54.698080,0.000000 25.262980,54.697970,0.000000 25.263090,54.697920,0.000000 25.263430,54.697850,0.000000 25.263710,54.697850,0.000000 25.264050,54.697900,0.000000 25.264350,54.698010,0.000000 25.264970,54.698360,0.000000 25.265150,54.698400,0.000000 25.265480,54.698410,0.000000 25.267540,54.698170,0.000000 25.267640,54.698190,0.000000 25.269980,54.697780,0.000000 25.271160,54.697470,0.000000 25.274150,54.696450,0.000000 25.278810,54.695110,0.000000 25.280890,54.694780,0.000000 25.284900,54.694380,0.000000 25.285310,54.694380,0.000000 25.288300,54.694750,0.000000 25.286540,54.699420,0.000000 25.286340,54.700280,0.000000 25.286370,54.700800,0.000000 25.286520,54.701460,0.000000 25.286610,54.701710,0.000000 25.286960,54.702270,0.000000 25.287170,54.702510,0.000000 25.288120,54.702510,0.000000</coordinates> 
</LineString>
</GeometryCollection>
<styleUrl>#roadStyle</styleUrl> 
</Placemark>
</Document>
</kml>
//-----------------------------------------------------------------------------------

Jan 13, 2009 at 8:46 AM

Hi radioman,

Sorry about my English ...

Offer the possibility to avoid the highway:

 

public

string MakeRouteUrl(PointLatLng start, PointLatLng end, string language, bool useHighway)

 

{

 

var highway = !useHighway ? "&mra=ls&dirflg=h" : "";

 

 

return

 

 

 

 

string.Format(

 

 

"http://maps.google.com/maps?f=q&output=dragdir&doflg=p&mra=ls&dirflg=h&hl={0}&q=&saddr=@{1},{2}&daddr=@{3},{4}{5}",

 

language, start.Lat.ToString(

CultureInfo.InvariantCulture),

 

start.Lng.ToString(

CultureInfo.InvariantCulture), end.Lat.ToString(CultureInfo.InvariantCulture),

 

end.Lng.ToString(

CultureInfo.InvariantCulture), highway);

 

}

public string MakeRouteUrl(string start, string end, string language, bool useHighway)

 

{

 

var highway = !useHighway ? "&mra=ls&dirflg=h" : "";

 

 

return

 

 

 

 

string.Format(

 

 

"http://maps.google.com/maps?f=q&output=dragdir&doflg=p&hl={0}&q=&saddr=@{1}&daddr=@{2}{3}", language,

 

start.Replace(

' ', '+'), end.Replace(' ', '+'), highway);

 

}

Jan 13, 2009 at 9:40 AM

Is it possible to get a text representation of the route?

Example:
1. Head west on XXX 0.7 km
2. Turn left at YYY 2.1 km

Coordinator
Jan 13, 2009 at 4:18 PM
thanks for tip of "Avoid Highways" mode.

..and about 'text representation' i specially choose JSON format to speed things up  instead of KML with text. I can create separate functions for that maybe...
Jan 14, 2009 at 8:55 AM
I look forward to this function.