You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 23, 2023. It is now read-only.
fromgeopyimportPointfromgeopy.distanceimportdistanceimportrandomdefgenerate_random_point(center, range_km):
""" Generate a random point within a given range (in km) of a center point. Returns a tuple of latitude and longitude. """# convert the range from km to degreesrange_degrees=distance(kilometers=range_km).kilometers/111# generate a random point within the range of the center pointwhileTrue:
# generate a random latitude and longitude within the range of the center pointlat=random.uniform(center.latitude-range_degrees, center.latitude+range_degrees)
lng=random.uniform(center.longitude-range_degrees, center.longitude+range_degrees)
point=Point(lat, lng)
# calculate the distance between the center point and the generated pointdist=distance(center, point).km# check if the distance is within the rangeifdist<=range_km:
break# return the latitude and longitude as a tuplereturnlat, lng# จุดกึ่งกลางcenter=Point(13.812075143604403, 100.50499488728185)
# ช่วงระยะระดับกิโลเมตรrange_km=20lat, lng=generate_random_point(center, range_km)
print('Latitude:', lat)
print('Longitude:', lng)