ios - finds a random destination point from current location is within the given distance GoogleMaps -
ios - finds a random destination point from current location is within the given distance GoogleMaps -
i making ios map using google maps.i want plot way on google maps current location random destination within given distance.
means app finds random destination point within given distance(e.g maybe 8 km or 15km ) (doesn't have accurately within distance long on sidewalk). random destination must on route,so user can run starting point designation point(random point).
how can designation point current location on google maps.any thought ..
thanks in advance.
use arc4random_uniform() calculate value that's 200,000 times bigger maximum amount want point move away user's current location. subtract half max value random number , split half max value.
double scale = 100000;
double maxnorthsouthchange = 2,000; //2,000 meters, 2k double randomnorthsouthchange = arc4random_uniform(maxnorthsouthchange*2*scale)/(2*scale)- maxnorthsouthchange*scale; //randomnorthsouthchange should range -maxnorthsouthchange +maxnorthsouthchange;
double maxeastwestchange = 2,000; //2,000 meters, 2k double randomeastwesthange = arc4random_uniform(maxeastwestchange*2*scale)/(2*scale)- maxeastwestchange*scale; //randomeastwesthange should range -maxeastwestchange + maxeastwestchange;
get lat/long of user's location. calculate number of kilometers per grade of longitude current latitude. (the number of kilometers per grade of latitude doesn't change.)
use values convert random alter values lat/long scale, , add together them user's current location.
the above code create random location within square box around user. max distance @ corners of box more max specify. if wanted create max random alter in location same in directions, you'd need rewrite code above utilize trig, said amount didn't have exact.
ios objective-c google-maps google-maps-api-3 map
Comments
Post a Comment