Get new Lat & Lon from speed

nasirgul
05-11-2008, 08:57 AM
Hello,
Any one wants to share knowledge regarding how to get new latitude and longitude from speed after defining default latitude and longitude. As in mine case I am not using GPS hardware just make pushpin as random and placing it in loop so that it will act as moving on map.
Hope to hear from you guys.
Regards.
Gul

Eric Frost
05-11-2008, 09:13 AM
I'm not sure I understand.. you want to get a new position based on the speed (and direction ?) and starting position?

Eric

nasirgul
05-11-2008, 09:42 AM
Well I have lat & lon as inputs and I want to calculate how much lat & lon has to change when a object is moving with a defined speed. Only the direction will be random in this case so that it will act as mine pushpin keep on moving.
Regards..

Eric Frost
05-11-2008, 11:02 AM
Does the pushpin need to stay on the road network? Or just move in a different random direction say every second?

Eric

nasirgul
05-11-2008, 11:07 AM
Yes it keeps on moving (specified interval,u can say 1 sec) after getting randomly speed which will keep on adding with input latitude & longitude.
thanks.

Eric Frost
05-11-2008, 11:28 AM
The speed is random or the direction is random or both?

nasirgul
05-11-2008, 11:36 AM
As per ys
The speed is random or the direction is random or both?
i want both.
Well in mine mind I will get ground speed from NMEA(GPRMC), and it will place in random then add it in both Lat & Lon so that it will keep on changing the speed randomly and because of this direction will change.... am I right.
Or you have some better idea.

Eric Frost
05-11-2008, 11:44 AM
I'm sorry.. I still don't get it. So you're getting actual speed from NMEA(GPRMC) or a device, but you don't want to plot an actual position.. just have it move randomly at that speed, changing direction every second?

I guess it might help to take a step back and explain the purpose of what you are trying to do.. :21m:

Eric

nasirgul
05-11-2008, 12:49 PM
Well let you describe from start. I want to develop an application which don't use hardware. In mine project i have inputs for Latitude & Longitude. I want to show it on map as random like moving object and calculate how much lat & lon has to change when a object is moving with a defined speed, Only the direction will be random(like moving onject). (its more like data comes from original GPS but in this i am not using GPS hardware, just act as dummy).

In mine mind i think if i will set some default speed in the beginning with lat & lon, it keeps on showing me next position if i will use
random(input speed);
so what do u think about it.

Nasir

Eric Frost
05-11-2008, 01:00 PM
Is it supposed to be a vehicle on the road network? Or a creature like a bird that could just fly anywhere?

What country or what part of the world are you working it? In the U.S., one degree of longitude is roughly equal to 50 miles or 80 km, and a degree of latitude is equal to 65 miles or 105 km.

It would be rough, but with some simple math and the Pythagorean theorem you could calculate how much to modify lat/lon each second for a particular speed and direction.

How far did you get with your code, what do you need help with specifically?

Eric

nasirgul
05-14-2008, 04:55 AM
Well its more like a dummy simulator which keeps on updating new location of latitude & longitude from the previous inserted lat & lon by the user(as I already told you in this case i am not using any hardware or any txt file). Its just looking like data comes from original GPS and it act as dummy simulator.I tried for it but cant able to get how I can do it.

Eric Frost
05-14-2008, 05:02 AM
How far have you gotten or do you need help to start the code?

Where are you stuck?

Eric

nasirgul
05-14-2008, 05:14 AM
I need some idea how I can start to do it.
Thanks.

Eric Frost
05-14-2008, 05:37 AM
I think the easiest way to get started with MapPoint programming is automating it through Excel VBA... there are some tutorials here:

Working With Excel and MapPoint - MP2K Magazine (http://www.mp2kmag.com/excel)

Eric

nasirgul
05-14-2008, 06:01 AM
I am working on my project from the last month using C# and interfacing with mappoint. I know basics. Just want to know any idea as I don't know how to get new lat, lon from calculation by inserting lat,lon & speed. Please give me hint.

Eric Frost
05-14-2008, 06:23 AM
OK given roughly:
one degree of longitude is 50 miles or 80 km
one degree of latitude is 65 miles or 105 km

Starting position Lat: +40.00 Lon: -90.00
Say you are going 30 miles per hour due north
You want the new lat/lon after a five second interval

Five seconds is 0.00139 of an hour, so in five seconds you would have traveled 0.0417 miles.

This is equivalent to 0.0642 degrees latitude, so the new position is Lat: +40.0642 Lon: -90.00

If you're going at an angle you have to use a little trig (Pythagorean theorem), but it's still simple math.

Where it could be tricky is if you need the point to stay on the road network.. then I think you may be able to leverage routing functionality in MapPoint and interpolate to get a five second interval.

Eric

nasirgul
05-14-2008, 06:55 AM
Thank you very much Eric. Now i got how i can code by looping which keep on locating new position after 5 sec. Just one thing more about the direction how can I continuously update direction on map after some seconds, suppose input from user be Lat:N & Lon:S.
Thanks once again.

nasirgul
05-16-2008, 04:18 AM
Hello,
Any body help me to get out of this problem. I need to have an infinite loop that executes every X seconds and show me next position. In other words, a timed / delayed loop. When I use timer it keeps on showing me present position of Lat & Lon which I inserted, not showing me the calculated next values. I tired alot but my application got stuck when i use
for(;;)
while(true)
while(0==0)Mine code is

public double Speed()
{
if (speed.Text == null || speed.Text.Length <= 0)
return 0;
double knots = Convert.ToDouble(speed.Text);

//Return KMPH
return knots * 1.852;
}

public double Distance()
{
////speed=distance/time.....so distance=speed*time
double time = 0.001388; /////(5 sec time interval)5/3600=0.001388hr
double distance = time * Speed(); //////////////////km/hr
return distance;
}


public double DoLatitude()
{
////1 Degree of Latitude = 110.6Km,68.703miles
double onedegreelat = Distance() * 110.6;
return onedegreelat;
}
public double DoLongitude()
{
////1 Degree of Longitude = 111.3Km*cos(Latitude),69.172miles*cos(Latitude)
double onedegreelon = Distance() * 111.3 * Math.Cos(Convert.ToDouble(latitude.Text));
return onedegreelon;
}

public double Lat()
{
double remlat = 0;
remlat = remlat + DoLatitude();
//remlat = "";
return remlat;
}
public double Lon()
{
double remlon = 0;
remlon = remlon + DoLongitude();
return remlon;

}
while (0 == 0)
{

textbox1.text= Lat().ToString();

textbox2.text= Lon().ToString();
}

I want my fn of Lat() & Lon() should be act as new calculated values so that my pushpin will move continuously.
Hope to hear from u guys.
thanks in advance.

Wilfried
05-17-2008, 11:28 AM
Hi,

you always return the same value. You have to place remLat and remLong as private members of the class instead of declaring them on the stack with always the same value (0).

nasirgul
05-18-2008, 06:46 AM
Hello Wilfried,
thank you for yours reply. Actually I am designing dummy simulator which will get data from one application and send to another application. For application one I am giving lat & lon and want to get map in second application. For doing as you said it works fine. It is updating new position on application second but my first application still getting hang up. I don't know about it. I tried on Google for this problem and found treads can solve this problem as it works fine in GUI for unlimited looping. But I don't know how I can use it in my application.

private void timer1_Tick(object sender, EventArgs e)
{
double remlat = 0;
double remlon = 0;
while (true)
{
remlat = remlat + DoLatitude();
remlon = remlon + DoLongitude();

double retValLat = remlat + Convert.ToDouble(latitude.Text);
double retValLon = remlon + Convert.ToDouble(longitude.Text);

string NMEA = "$GPGGA" + "," + "UTCTime" + "," + (retValLat.ToString()) + "," + Pole1.Text + "," + (retValLon.ToString()) + "," + Pole2.Text;
byte[] nmea = System.Text.Encoding.ASCII.GetBytes(NMEA);
if (clientSocket != null)
{ clientSocket.Send(nmea); }
//timer1.Interval=(9000);
Thread.Sleep(10000);
//return remlat;

Console.WriteLine(nmea);
}


Regards.

Wilfried
05-19-2008, 07:16 AM
Hi,

You still have remlat and remlon on the stack and eveytime initialized to null.

On which code line does your program stops responding?

nasirgul
05-19-2008, 07:49 AM
Hello,
It don't show any stuck point. Actually I use to run exe file. As in order to connect two applications i have to give port number for this i should have to open as exe file. When i tried to execute from visual studio environment it still getting hangup without showing any line of stuck.
Any idea how to overcome this problem.

Wilfried
05-19-2008, 07:58 AM
Hi,

you have to step with the debugger trough the code line by line until you find a line that never returns.

nasirgul
05-19-2008, 08:12 AM
I did it but still it is return in continuous way. I think I will try thru treads as I am looking one example which is doing what I want but its bit complicated.
thanks alot for yours efforts.
Nasir

 
Web mp2kmag.com
mapforums.com