Skip to content Skip to sidebar Skip to footer

Generate Random Locations Nearby My Location

I would like to generate random latitude/longitude pairs inside the circle surrounding my location. Currently i have implemented a location listener and everytime i get a new locat

Solution 1:

How about randomly generating the coordinates yourself? Using the current location you could set limitations to these numbers. Using the current coordinates and the radius you get the span for the random numbers. Span for random new X = Old X +- radius

I'd suggest generating a random number between -1 and 1, then multiply it with the radius. This means that the max value for the generated coordinate is the radius (and min is -radius). Adding this value to the current location coordinate gives you a value between Old X +- radius. Summary:

(Random number between -1 and 1)*radius + (old x) = new x within radius of old x.

Example code for the random number (OBS! from 0 to 1):

import java.util.Random;

Randomr=newRandom();
doublezeroToOne= r.nextInt(1001) / 1000

Here's the java documentation on random: Random

Solution 2:

it seems like a good thing. if you want to take a look : http://android-er.blogspot.com/2011/02/get-list-of-address-from-location-using.html

i think, normally it have been working but i couldn't try to setup it on device

Post a Comment for "Generate Random Locations Nearby My Location"