-3

As the title suggests, I am trying to generate a coordinate based on another coordinate that is within an x mile (or whichever unit is most convenient) radius of the inputted one.

As an example:

  • I am given a geographic coordinate (lat, lon) of 39.083056, -94.820200.
  • I want to be returned another set of coordinates that is within a x miles radius of that coordinate, such as 39.110998, -94.799668.
  • The x mile radius isn't as important as the fact that the returned coordinates are within that x mile radius.

I have searched and searched, but I must be searching the wrong thing because all the posts that I have been able to find seem like they get very close to what I am trying to do but aren't quite hitting the nail on the head.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Zach Yarid
  • 55
  • 5
  • Yes, show us how your current code looks like and then we might help you. – Juan Sep 13 '17 at 04:59
  • If you have searched and search its usually a good idea to list what you found and why it didn't meet your needs. You could easily modify the answer here: https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters – Jeremy Thompson Sep 13 '17 at 05:02
  • My bad guys. I was so burnt out by the time I had posed this question on here. I had a long day and just wanted to go to bed :P I will be sure to post what I have tried the next time I ask a question! – Zach Yarid Sep 13 '17 at 21:08

1 Answers1

0

I'm sorry you're being downvoted to oblivion. I understand it can be frustrating trying to search for something without knowing what exactly to search for.

You may be interested in Orthodromic Lines/Distances: wiki. If this answer doesn't fulfil your needs, at least you have a new term to google and hopefully will lead you to one that does suit.

You could try using the Geo library. Its documentation is on the sparse side, but it does contain a method that could be useful to you: CalculateOrthodromicLine(startPoint, heading, distance)

A pseudocode would be something as simple as this:

var startPoint = new Coordinate(lat, long);
var heading = Random between 0 and 360 degrees
var distance = Random between 0 and X metres
var endPoint = //<-- et voila!
    GeoContext.Current.GeodeticCalculator
    .CalculateOrthodromicLine(startPoint, heading, distance)
    .Coordinate2;

Edit: As mentioned in the wiki, the Earth is not a perfect sphere, but a spheroid instead. The library's GeoContext.Current by default uses its Spheroid calculations, so you should be okay.

Good luck!

NPras
  • 3,135
  • 15
  • 29
  • NPras, thank you for your input. This ended up working out for me. Moving forward, I will be sure to post what I've tried. – Zach Yarid Sep 13 '17 at 21:06
  • Yeah, there are heaps of blatantly lazy people coming here asking other people to do their homework. This did not seem like one of those, and is actually an interesting question that I've asked myself but never bothered to look up. I say it's a win for both of us! – NPras Sep 14 '17 at 04:08
  • I will admit, I am in an Advanced C# ASP.NET course but it is merely advanced in nature. We are working on form submission and validation right now. Something I taught myself quite some time ago! Again, thank you for your help! This post was about a different side project that I've picked back up, but I will be mindful of how I post in the future! – Zach Yarid Sep 15 '17 at 13:37