Get Location Points (LatLng) List between two points (start and end)

Topics: Help
Nov 14, 2012 at 11:19 AM

Hi all,

I would like to know if someone could tell me how can i get a list of location points (steps) between 2 address.

The constraint is that i need to do it, without a map.. 

(It will be inside a .NET web-service actually)

Thx for any help :)

Nov 14, 2012 at 11:26 AM

check provider functions

Nov 14, 2012 at 12:48 PM

Hi,

I checked the provider class, and made some test, but sadly the object is always null

var gDirections = new GDirections();

var startPointLatLng = new PointLatLng(**.*******, **.*******);           

var endPointLatLng = new PointLatLng(**.*******, **.*******);

var provider = GMapProviders.GoogleMap;

var x = provider.GetDirections(out gDirections, startPointLatLng, endPointLatLng, false, false, false, false, true);

but gDirections is always null

 

Any thoughts?

Nov 14, 2012 at 12:56 PM

try other location

Nov 14, 2012 at 1:16 PM
radioman wrote:

try other location

If you mean other start and end points.. yeah i tried and still same null value..

If you meant something else? tell me ;)

Nov 14, 2012 at 4:38 PM

works just fine ;}

 var p1 = new PointLatLng(54.6961334816182, 25.2985095977782);
 var p2 = new PointLatLng(54.7061334816182, 25.3085095977783);

 GDirections ss;
 var xx = GMapProviders.GoogleMap.GetDirections(out ss, p1, p2, false, false, false, false, false);

summary: Žirmūnų gatvė
duration: 4 mins
distance: 1.2 mi
start_address: Šeimyniškių gatvė, Vilnius district municipality 09008, Lithuania
end_address: P. Vileišio gatvė 20, Vilnius district municipality 10302, Lithuania
copyrights: Map data ©2012 Tele Atlas
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 328 ft
html_instructions: Head <b>east</b>
----------------------
travel_mode: DRIVING
duration: 2 mins
distance: 0.7 mi
html_instructions: Exit the roundabout onto <b>Žirmūnų gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.2 mi
html_instructions: Turn <b>right</b> onto <b>Šilo gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 427 ft
html_instructions: Make a <b>U-turn</b> at <b>Antakalnio gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 282 ft
html_instructions: Slight <b>right</b> toward <b>P. Vileišio gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 164 ft
html_instructions: Turn <b>right</b> onto <b>P. Vileišio gatvė</b><div style="font-size:0.9em">Destination will be on the right</div>
summary: A1/E85
duration: 1 hour 24 mins
distance: 105 km
start_address: Vilniaus gatvė 6, Vilnius district municipality 01013, Lithuania
end_address: A. Mapu gatvė 2-20, Kaunas district municipality 44284, Lithuania
copyrights: Map data ©2012 Google, Tele Atlas
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.2 km
html_instructions: Head <b>north</b> on <b>Vilniaus gatvė</b> toward <b>Tilto gatvė</b>
----------------------
travel_mode: DRIVING
duration: 2 mins
distance: 1.3 km
html_instructions: Turn <b>left</b> onto <b>A. Goštauto gatvė</b>
----------------------
travel_mode: DRIVING
duration: 5 mins
distance: 4.0 km
html_instructions: Turn <b>left</b> to merge onto <b>Geležinio Vilko gatvė</b>
----------------------
travel_mode: DRIVING
duration: 10 mins
distance: 9.4 km
html_instructions: Continue onto <b>Savanorių prospektas</b>
----------------------
travel_mode: DRIVING
duration: 57 mins
distance: 84.7 km
html_instructions: Continue onto <b>A1/E85</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.5 km
html_instructions: Take the exit toward <b>Senamiestis/Aleksotas</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.2 km
html_instructions: Turn <b>left</b> onto <b>Kleboniškio gatvė</b>
----------------------
travel_mode: DRIVING
duration: 7 mins
distance: 4.3 km
html_instructions: Continue onto <b>Jonavos gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.5 km
html_instructions: At the roundabout, take the <b>3rd</b> exit and stay on <b>Jonavos gatvė</b>
----------------------
travel_mode: DRIVING
duration: 1 min
distance: 0.2 km
html_instructions: Turn <b>right</b> onto <b>A. Mapu gatvė</b><div style="font-size:0.9em">Destination will be on the right</div>
A1/E85, Map data ©2012 Google, Tele Atlas
Vilniaus gatvė 6, Vilnius district municipality 01013, Lithuania -> A. Mapu gatvė 2-20, Kaunas district municipality 44284, Lithuania
105 km
1 hour 24 mins
DRIVING | 0.2 km | 1 min | Head <b>north</b> on <b>Vilniaus gatvė</b> toward <b>Tilto gatvė</b>
DRIVING | 1.3 km | 2 mins | Turn <b>left</b> onto <b>A. Goštauto gatvė</b>
DRIVING | 4.0 km | 5 mins | Turn <b>left</b> to merge onto <b>Geležinio Vilko gatvė</b>
DRIVING | 9.4 km | 10 mins | Continue onto <b>Savanorių prospektas</b>
DRIVING | 84.7 km | 57 mins | Continue onto <b>A1/E85</b>
DRIVING | 0.5 km | 1 min | Take the exit toward <b>Senamiestis/Aleksotas</b>
DRIVING | 0.2 km | 1 min | Turn <b>left</b> onto <b>Kleboniškio gatvė</b>
DRIVING | 4.3 km | 7 mins | Continue onto <b>Jonavos gatvė</b>
DRIVING | 0.5 km | 1 min | At the roundabout, take the <b>3rd</b> exit and stay on <b>Jonavos gatvė</b>
DRIVING | 0.2 km | 1 min | Turn <b>right</b> onto <b>A. Mapu gatvė</b><div style="font-size:0.9em">Destination will be on the right</div>
Nov 15, 2012 at 8:26 AM
Edited Nov 15, 2012 at 12:04 PM

Hi,

 

Yes indeed, it works perfectly :)

I tried in the console application or winforms, and i have all what i need...

But once I'm trying to do the same in a webservice, same null value :'(

I even have made a class in the console application project which is doing the same, 

but once i call that class from the webservice.. it doesn't work...

Does the class has some limitation with a web application?

 

Thanks (and really great work btw ;))

Nov 15, 2012 at 8:04 PM

debug, and find whats wrong

Nov 16, 2012 at 1:11 PM
radioman wrote:

debug, and find whats wrong

I did it...

No error, but the out value (gDirections) remains null...

In the console application it works, but not in the webservice...

 

Regards

Nov 16, 2012 at 1:24 PM

step in the function, and check why it get null

Nov 16, 2012 at 8:31 PM

Hi,

thx for the answer :)

Ok, I debugged into the function and it seems that there is an issue with the singleton instance of the cache

 Cache.Instance.GetContent(urlEnd, CacheType.DirectionsCache)   (null exception)

Maybe because the fact that it's a web application, the instance of the cache can't be instancied..?

Do you have any workaround?

 

Regards

Nov 16, 2012 at 8:39 PM

hm, can you check cache constructors ?

Nov 18, 2012 at 2:01 PM

Hello,

It works!! :D

Actually as you advised, i checked a bit more deep in the class..

And then in a property called "CacheLocation" this code was causing an exception:

if(ImageCache is SQLitePureImageCache)           

{             

 (ImageCache as SQLitePureImageCache).CacheLocation = value;           

}

I guess that as it's a web application, the path of cache can't be correct..

So i just removed the code, and it works perfectly :D

 

Thanks again for your help (and this work ! )

Nov 18, 2012 at 2:17 PM

no, that doesn't solve anything, whats the real exception?

Nov 19, 2012 at 6:10 PM

Actually, the problem is the path of the cache:

value = "\GMap.NET\"

and should be 

value = C:\***\***\AppData\Local\GMap.NET\

 

and the exception is:

{"Absolute path information is required."}

System.ArgumentException was caught  Message=Absolute path information is required.  Source=GMap.NET.Core  StackTrace:       at GMap.NET.CacheProviders.SQLitePureImageCache.set_CacheLocation(String value)       at GMap.NET.Internals.Cache.set_CacheLocation(String value) 

Regards

Nov 19, 2012 at 6:17 PM

hm, thats strange, can you test this? ..maybe on the webservice it doesn't work:

string dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)

Nov 19, 2012 at 6:58 PM
Edited Nov 19, 2012 at 6:59 PM

Ok i found why :)

Actually the iis must be the version 7.5

and the application pool of the web application must have -> LoadUserProfile = true & Identity = LocalSystem

otherwise System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) will not return anything

(if it's iis 6 there is a way to load user profile in the code before you try to access per-user settings.)

 

(or in your code if it's a web application, maybe you can specify another path (more web oriented) ;) )

 

then, great! XD

Thanks again, nice work! ;)

Nov 19, 2012 at 7:15 PM
Edited Nov 19, 2012 at 7:17 PM

by default Network Service doesn't has disk write access, therefore i've disabled cache in such case, at least it should work anyway

 p.s. http://stackoverflow.com/questions/7245366/where-to-write-a-log-file

Dec 7, 2013 at 8:24 PM
Edited Dec 7, 2013 at 8:24 PM
Hi! Just small remark, actually the cache is not disabled in this case yet. I mean Cache.cs line 49: "location" can't be null or empty after setting it at line 46.
Jan 13, 2014 at 7:18 AM
hi
i need to add my own points between start ,end
how can i do ?
Dave