Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by WilliamKattrup · Jan 03, 2015 at 02:54 PM · distancelocationgps

Length between GPS-locations

Hey all Unity developers and programmers :) i am developing a game where i need the length between two GPS-locations in KM. lets say we have two locations points like this: (87.090329, 25.883993) (89.393944, 31.92494) how can i get the length between these two positions? anyone know? if you could code it for me in c#

Best Regards :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Jan 03, 2015 at 02:56 PM

The most common solution is to approximate using the Haversine formula.

Pseudo-code:

 var a = sin²(Δφ/2) + cos φ1 * cos φ2 * sin²(Δλ/2);
 var c = 2 * atan2( √a, √(1−a) );
 var d = R * c;

where: φ is latitude, λ is longitude, R is radius of the Earth (use 6,371km if unsure)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WilliamKattrup · Jan 03, 2015 at 03:34 PM 0
Share

Hey thanks for the answer :) but there is an error it says unexpected symbol :

avatar image Z2City · Jan 03, 2015 at 04:07 PM 2
Share

that's cause if you haven't noticed, its PSEUDO-code.

avatar image
-2

Answer by N1warhead · Jan 03, 2015 at 04:18 PM

The easiest way I would think is get a map of a place you need..

Such the entire USA.

Okay, find the points of GPS you would like. Then find a line of sight distance, then divide the distance or something like that.

That way you can calculate the distance per grid.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Jan 03, 2015 at 04:40 PM 0
Share

Perhaps you'd be so kind as to expand your answer with an example...? Say, how would you use this approach to calculate the distance between London (51.5,-0.12) and Paris (48.85,2.33)?

avatar image N1warhead · Jan 03, 2015 at 04:59 PM 0
Share

Go to google Earth. find the GPS Numbers for each given location...

$$anonymous$$ake a custom grid.

Lets say 10 x 10 grid squares. Okay.

Well, it's 282.3 miles to the locations. gives you 28.3 miles per grid square.

I would use a more advanced grid that could cover literally every single possible GPS location. Such as a 4096 x 4096 pixel image. As that would give you a total of 16,777,216 pixels.

That way you can find the most $$anonymous$$ute distance to calculate given the formula I used above.

It's not hard, all you have to do is calculate the distance per each pixel geographically, which depends on the size of your grid. ideally you would probably want it in the range of feet per pixel not miles. That way it is more accurate.

avatar image N1warhead · Jan 03, 2015 at 05:02 PM 0
Share

It's hard to explain, I had to use this said formula to make an advanced neural network to calculate weather patterns and distances to places.

It's not easy to explain, I knew for awhile what I wanted to do, just didn't really understand how, until I did the above, which it may not be directly that hard, but it is. At least to $$anonymous$$ch the computer the distances and stuff it is.

avatar image Scribe · Jan 04, 2015 at 12:18 AM 0
Share

The problem I would have with this is that no 2D representation of the earth (a map) is actually uniformly scaled at every point, for example google maps uses the Gall stereographic model, so two squares of the same size, one at the equator and one at for example 66 degrees latitudinally, the square at the equator will actually contain more 'area' than the other, as the length of the equator is longer than the length of the arctic circle (at 66'33) so the scale that the land is drawn at is smaller.

I think it could be a good approximation over short distances, but I don't think you should use it for world map type distances.

avatar image N1warhead · Jan 04, 2015 at 12:20 AM 0
Share

Yeah that is true, I wasn't trying to go for a world wide map when I made my program, it was only for the state I live in... Which is a much smaller area to do things with lol.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Input.location.start always times out 1 Answer

Device altitude change not accurate 0 Answers

Location Service on iOS 1 Answer

Get Android devices current country location 0 Answers

How to import GPS location coordinates from Android device? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges