Reputation: 1
I need to generate random LatLng points in a polygon defined on the maps suppose my first point beging at (x,y) and next latlng will be greater than 100 meters and less that 500 meters
Upvotes: 0
Views: 616
Reputation: 37717
This is quite simple.
Upvotes: 0
Reputation: 2648
You could try something like below, this uses a HashMap to create unique and random numbers:
public void getRandomPosistions(int endPoint, int total)
{
Set<Point> set = new HashSet<Point>();
Random position = new Random();
Point point;
Point usedPos = new Point();
// Starting Position
usedPos.x = 100;
usedPos.y = 100;
set.add(usedPos);
do
{
point = new Point();
point.x=position.nextInt(endPoint);
point.y=position.nextInt(endPoint);
set.add(point);
}
while(set.size() < (total));
List<Object> positionList = new ArrayList<Object>(set);
}
Upvotes: 1