is there a way of calculation distance in geolocation?

Get help using Construct 2

Post » Sat Oct 17, 2015 5:16 am

I was wondering if there's a way of tracking distance travelled using geolocation. it will be shown as a progress bar so it doesn't need to be accurate to a map it just needs to show distance travelled in metres/feet.

thank you
B
7
S
1
Posts: 54
Reputation: 527

Post » Tue Oct 20, 2015 10:22 pm

I don't know exactly , but have a look at this http://www.movable-type.co.uk/scripts/latlong.html
What I would do:
Go to google maps, set your destination to lat0,long0, (zoom in and click until you find it) then go to lat 1 and see how many km are, then divide one by the other to find out a multiplication factor. Do the same for the longitude. Use Google dev console to modify gps coordinates so you can test your code
But from the above link, I can see that 1 degree = 111.2 km, so you can test using this value as a multiplication factor for the values that you get from Browser.location
B
83
S
21
G
23
Posts: 521
Reputation: 18,764

Post » Tue Oct 20, 2015 10:32 pm

To actually calculate the the distance traveled, create 3 variables: DistanceTraveled, LastLocationLat and LastLocationLong
Add geolocation plugin to your project then every time the geolocation is updated do like this:
DistanceTraveled = DistanceTraveled + distance(LastLocationLat,LastLocationLong,Geolocation,Latitude,Geolocation.Longitude)
LastLocationLat = Browser.Lat
LastLocationLong = Browser.Long
You cand find the distance(X1,Y1,X2,Y2) in System object, under math section I think
B
83
S
21
G
23
Posts: 521
Reputation: 18,764

Post » Sun Nov 08, 2015 5:27 pm

Thank you so much this helped a lot
B
7
S
1
Posts: 54
Reputation: 527


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests