Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,

i am sitting on a game which i am programming at the time and i am facing the following problem:

The game has a predefined exisiting polygon on a GMaps.net API using GoogleMaps as GMapsProvider. Now i need a random valid address which is existing inside the polygon on the map. Since i dont know how to achieve this without having a list of all towns, streets and house numbers existing inside the polygon (would be waaaaay to big of a list to collect it by hand) i am asking for your help. I dont know how i can realize this.

Thank you very much!

What I have tried:

Nothing, since i dont have a clue. Lol
Posted
Updated 18-Sep-17 0:24am
v2

1 solution

Address are arbitrary definitions on the landscape. You can, however pick out an arbitrary locations. Do this by using the rand function to generate GPS coordinates with the following two general possibilities.

1) Polygon is rectangular aligned, in phase, with the coordinate system: simply range the randomized values between the max/min longitude and latitude of your rectangle.
2) General Case: arbitrary polygon. Again, get max, min GPS coordinates that encompass entire polygon. Generate random value within this range. Test (Perhaps a google function exist) if the coordinates are with this range.

Now, with valid coordinates, have google convert them to the nearest address to those coordinates. (Like when you click on a google map and it gives you whats there)

Now - if you have lakes and parks and such to worry about, and in general you would, you need decide how to handle it. Redraw until you get a hit with an address, for example.

The above is logically functional - not necessarily a best solution as I don't use google functionality. There may be some very helpful existing options that shortcut the above.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900