We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

# How to find the last coordinates using javascript RSS

Last post Jan 30, 2020 05:36 AM by yij sun

• progy85

Member

65 Points

194 Posts

### How to find the last coordinates using javascript

hello,

my problem: I have my two different coordinate and I want to calculate for different coordinates how much is distance from first and second coordinates.

My code works, but I don't have any idea how to find the last coordinates with javascript.

Example:

Latitude, Longitude
1,2

New coordinates (after refresh again, its every second.)

Need to calculate between 1,2(last coordinates) and new coordinates.

New coordinate:
Latitude, Longitude:
5, 6

1,2 - 5,6.

This code works:

Calculate coordinate:

```        function distance(lat1, lon1, lat2, lon2, unit) {
if ((lat1 == lat2) && (lon1 == lon2)) {
return 0;
}
else {
var radlat1 = Math.PI * lat1 / 180;
var radlat2 = Math.PI * lat2 / 180;
var theta = lon1 - lon2;
var radtheta = Math.PI * theta / 180;
if (dist > 1) {
dist = 1;
}
dist = Math.acos(dist);
dist = dist * 180 / Math.PI;
dist = dist * 60 * 1.1515;
if (unit == "K") { dist = dist * 1.609344 }
if (unit == "N") { dist = dist * 0.8684 }
return dist;
}
}```

Calling coordinate:

`var dist = distance_on_geoid(1, 2, position.coords.latitude, position.coords.longitude);`

This is my code for calculate all coordinates.

```            var i = 0;
var j = dist;
if (result === 0)
result = Number(i) + Number(j);
else
result = result + j;```

SUM:

`\$("#dist").html(result);`

For SUM all coordinates

• yij sun

Contributor

4190 Points

1637 Posts

### Re: How to find the last coordinates using javascript

Jan 30, 2020 05:36 AM|yij sun|LINK

Hi progy85,

As far as I think,you could put coordinates into an array and check if the pointer is more than the array length.

```var Latitude='';
var Longitude='';
var xx=[
{
"Latitude":"1",
"Longitude":"2",
},
{
"Latitude":"5",
"Longitude":"6",
}
];
\$.(each)(xx,function(i,item){
if(i==item.length-1)
....
})```

Best regards,

Yijing Sun

ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >