?
Solved

Need to get random lat/long location given country

Posted on 2011-03-04
11
Medium Priority
?
2,224 Views
Last Modified: 2012-08-14
I have a need to be able to get a random lat/long location within a specified country.  I've searched and seen solutions that call a service getting a random location until it returns one in the country desired, and saw the question on Experts Exchange about getting a list of 1000 for a specified country, but none of those solutions will work for me.

I just need to call an API or service passing in a country code and getting a random lat/long that is within that country.  Repeated calls should give a reasonable dispersion across the country.

Thanks!
0
Comment
Question by:ktschmidt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 49

Expert Comment

by:dbrunton
ID: 35039078
Suggestion

You should be able to get a country and then within that country get a town or city.  Then get the latitude and longitude for that location.

For example http://www.findlatitudeandlongitude.com/ gives you latitude and longitudes of towns or cities and there are probably databases that contain town and city listings for various countries.
0
 
LVL 63

Expert Comment

by:☠ MASQ ☠
ID: 35043076
Is there a finite list of countries (like a typical website drop-down) or do you have to allow for ANY country to be entered?
Suggest in the first version you simply link the country to its capital city and use the reference for that location.
0
 

Author Comment

by:ktschmidt
ID: 35044014
Thanks for the suggestions.

Unfortunately, I don't have a finite list, I need to be able to get a random location in a country for any country, and do this for 40K records.  So yes, I could go compile a list of cities in every country and do as the first reply suggested, but I was both hoping to not have to get a list for every country and even that wouldn't suffice as for some countries I may have 100s or 1000s of records and I'd get the same city several times and I need it more random than that.  I could introduce some small random lat/long offset to address the latter but I'd still rather not have to get a list of cities for every country.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 49

Expert Comment

by:dbrunton
ID: 35044523
Why compile a list when they are already made?

See http://earth-info.nga.mil/gns/html/namefiles.htm
0
 

Accepted Solution

by:
ktschmidt earned 0 total points
ID: 35184033
I don't need a list of countries, I need random latlon within a country.

I went ahead and implemented something myself where I identify the latlon rectangle around a country then call Google's API with a random point within it to see if it is in the country.  If so, add to my list, if not, keep trying.
0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35184205
ktschmidt:
I gather that your solution is approximately correct given that you are up to having a small country compared to the curvature of the earth - and the correctness of the Google data.

For a larger country you have to make an effort to make all the cells in your bounding surface equal when it comes to area of it to get a non-biased distribution: equilateral spherical triangles come to my mind of course ... All depending on the precision needed of course. Imagine generating random points  
over the US or Canada, or even worse, over Russia...
0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35184226
Before knowing that this question was up to be closed I suggested a more general solution - and more exact!
0
 

Author Comment

by:ktschmidt
ID: 35184347
@ghemstrom, yes, you bring up some good points about the exactness.  If you happen to have all the equations handy to implement it, let me know :)

For my purposes, the rectangle worked well enough.
0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35184387
No I do not have it handy, sorry - and I understand that the rectangle would do if it were not for lottery purposes or something - really, I am curious about the purpose?
0
 

Expert Comment

by:South Mod
ID: 35225165
All,
 
Following an 'Objection' by ghemstrom (at http://www.experts-exchange.com/Q_26901676.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question