本文整理汇总了Python中location.Location.getDistance方法的典型用法代码示例。如果您正苦于以下问题:Python Location.getDistance方法的具体用法?Python Location.getDistance怎么用?Python Location.getDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类location.Location
的用法示例。
在下文中一共展示了Location.getDistance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise GeneralPogoException("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
logging.info("Walking %f meters. This will take %f seconds..." % (dist, dist / step))
while dist > epsilon:
logging.debug("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
示例2: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise Exception("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
while dist > epsilon:
logging.info("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
示例3: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, speed):
# speed in m/s
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# don't divide by zero, bad stuff happens
if dist == 0:
return
divisions = dist/speed
dlat = (latitude - olatitude)/divisions
dlon = (longitude - olongitude)/divisions
logging.info("(TRAVEL)\t-\tWalking "+str(dist)+"m at "+str(speed)+"m/s, will take approx "+str(divisions)+"s")
while dist > speed:
latitude-=dlat
longitude-=dlon
self.setCoordinates(latitude, longitude)
time.sleep(1)
dist = Location.getDistance(latitude, longitude, olatitude, olongitude)
#final move
self.setCoordinates(olatitude, olongitude)
示例4: walkToAndCatch
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkToAndCatch(session,olatitude, olongitude, epsilon=10, step=4):
logging.debug("Calculate distance to destination(%f,%f) - %im/s",
olatitude, olatitude, step)
latitude, longitude, _ = session.getCoordinates()
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
divisions = dist / step
if (divisions == 0):
session.setCoordinates(
olatitude,
olongitude
)
logging.debug("Current location(%f,%f) - %im to destination",
latitude, longitude, int(dist))
return
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
logging.info("(%f,%f) -> (%f,%f) : %im in %i s",
latitude, longitude,
olatitude, olongitude,
int(dist), int(dist / step) + 1)
logging.debug("Start Walk")
while dist > epsilon:
if dist < step:
session.setCoordinates(
olatitude,
olongitude
)
logging.debug("Current location(%f,%f) - %im to destination",
latitude, longitude, int(dist))
break
latitude -= dLat
longitude -= dLon
session.setCoordinates(
latitude,
longitude
)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
logging.debug("Current location(%f,%f) - %im to destination",
latitude, longitude, int(dist))
catchAllPokemon(session)
time.sleep(1) # 1 sec
示例5: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5, delay=10):
if step >= epsilon:
raise GeneralPogoException("Walk may never converge")
if self.location.noop:
raise GeneralPogoException("Location not set")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
logging.info("Walking %f meters. This will take ~%f seconds..." % (dist, dist / step))
steps = 1
while dist > epsilon:
logging.debug("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
steps %= delay
if steps == 0:
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
steps += 1
# Finalize walk
steps -= 1
if steps % delay > 0:
time.sleep(delay - steps)
self.setCoordinates(
latitude,
longitude
)
示例6: find_pokemon
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def find_pokemon(session, sort=False, num_return=5, radius=10):
# Get Map details and print pokemon
logging.info('Finding nearby Pokemon')
cells = session.getMapObjects(radius=radius)
latitude, longitude, _ = session.getCoordinates()
p_d = []
pokemons = [pokemon for cell in cells.map_cells for pokemon in cell.wild_pokemons]
distances = [None] * len(pokemons)
for ind, pokemon in enumerate(pokemons):
# Log the pokemon found
logging.info("Found %s at %f,%f" % (
mappings.id_name[pokemon.pokemon_data.pokemon_id],
pokemon.latitude,
pokemon.longitude
))
distance = Location.getDistance(
latitude,
longitude,
pokemon.latitude,
pokemon.longitude
)
# Finds distance to pokemon
if sort:
heapq.heappush(p_d, (distance, pokemon))
else:
distances[ind] = distance
if sort:
try:
distances, pokemons = zip(*heapq.nsmallest(num_return, p_d))
except:
distances, pokemons = [], []
return distances, pokemons
示例7: findClosestPokemon
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def findClosestPokemon(session):
# Get Map details and print pokemon
logging.info("Printing Nearby Pokemon:")
cells = session.getMapObjects()
closest = float("Inf")
pokemonBest = None
latitude, longitude, _ = session.getCoordinates()
for cell in cells.map_cells:
for pokemon in cell.wild_pokemons:
# Log the pokemon found
logging.info("%i at %f,%f" % (
pokemon.pokemon_data.pokemon_id,
pokemon.latitude,
pokemon.longitude
))
# Fins distance to pokemon
dist = Location.getDistance(
latitude,
longitude,
pokemon.latitude,
pokemon.longitude
)
# Greedy for closest
if dist < closest:
pokemonBest = pokemon
return pokemonBest
示例8: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise GeneralPogoException("Walk may never converge")
if self.location.noop:
raise GeneralPogoException("Location not set")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("%s%s|%s| Walking %f meters. This will take %f seconds..." % ('\033[93m', "➜ ".decode('utf-8'), st , dist, dist / step))
logging.info("Walking %f meters. This will take %f seconds..." % (dist, dist / step))
while dist > epsilon:
logging.debug("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
示例9: walkTo
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise GeneralPogoException("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
logging.info("Walking %f meters. This will take %f seconds..." % (dist, dist / step))
print '~'*5,round((dist/(dist / step))*3.6,3),'km/h','~'*5
dist_max = dist
p = ProgressBar(max_value=dist_max)
while dist > epsilon:
logging.debug("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
p.update(dist_max-dist)
p.update(dist_max)
示例10: findBestPokemon
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def findBestPokemon(session,args):
# Get Map details and print pokemon
logging.info("Finding Nearby Pokemon:")
cells = session.getMapObjects()
closest = float("Inf")
best = -1
pokemonBest = None
latitude, longitude, _ = session.getCoordinates()
logging.info("Current pos: %f, %f" % (latitude, longitude))
for cell in cells.map_cells:
# Heap in pokemon protos where we have long + lat
pokemons = [p for p in cell.wild_pokemons] + [p for p in cell.catchable_pokemons]
for pokemon in pokemons:
# Normalize the ID from different protos
pokemonId = getattr(pokemon, "pokemon_id", None)
if not pokemonId:
pokemonId = pokemon.pokemon_data.pokemon_id
# Find distance to pokemon
dist = Location.getDistance(
latitude,
longitude,
pokemon.latitude,
pokemon.longitude
)
# Log the pokemon found
logging.info("Found a %s, %f meters away \n" % (
pokedex[pokemonId],
dist
))
rarity = pokedex.getRarityById(pokemonId)
# Greedy for rarest
if rarity > best:
pokemonBest = pokemon
best = rarity
closest = dist
# Greedy for closest of same rarity
elif rarity == best and dist < closest:
pokemonBest = pokemon
closest = dist
if pokemonBest != None:
logging.info(pokedex[pokemonBest.pokemon_data.pokemon_id] + " appears to be the rarest Pokemon @ location. Let's catch him!")
else:
logging.info("Sorry charlie, no Pokemon here. Enter a new location.")
doSnipe(session,args)
return pokemonBest
示例11: walk_to
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def walk_to(self, olatitude, olongitude, epsilon=10, step=7.5, pause=0.5, step_lambda=None, step_lambda_kwargs={}, step_call=1):
if step >= epsilon:
raise Exception("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.get_coordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
count = 0
while dist > epsilon:
if count % step_call == 0 and step_lambda:
step_lambda(**step_lambda_kwargs)
#logging.info("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.set_coordinates(
latitude,
longitude
)
time.sleep(pause)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
count += 1
示例12: findBestPokemon
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def findBestPokemon(session, pids=None):
# Get Map details and print pokemon
logging.info("Finding Nearby Pokemon:")
cells = session.getMapObjects()
closest = float("Inf")
best = -1
pokemonBest = None
latitude, longitude, _ = session.getCoordinates()
logging.info("Current pos: %f, %f" % (latitude, longitude))
for cell in cells.map_cells:
# Heap in pokemon protos where we have long + lat
pokemons = [p for p in cell.wild_pokemons] + [p for p in cell.catchable_pokemons]
for pokemon in pokemons:
# Normalize the ID from different protos
pokemonId = getattr(pokemon, "pokemon_id", None)
if not pokemonId:
pokemonId = pokemon.pokemon_data.pokemon_id
# If pids exist, only target those
if pids!=None and not pokemonId in pids:
pass
else:
# Find distance to pokemon
dist = Location.getDistance(
latitude,
longitude,
pokemon.latitude,
pokemon.longitude
)
# Log the pokemon found
logging.info("%s, %f meters away" % (
pokedex[pokemonId],
dist
))
rarity = pokedex.getRarityById(pokemonId)
# Greedy for rarest
if rarity > best:
pokemonBest = pokemon
best = rarity
closest = dist
# Greedy for closest of same rarity
elif rarity == best and dist < closest:
pokemonBest = pokemon
closest = dist
return pokemonBest
示例13: findBestPokemon
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def findBestPokemon(session):
# Get Map details and print pokemon
logging.info("Finding Nearby Pokemon:")
cells = session.getMapObjects()
closest = float("Inf")
best = -1
pokemonBest = None
listPokemons = []
latitude, longitude, _ = session.getCoordinates()
logging.info("Current pos: %f, %f" % (latitude, longitude))
for cell in cells.map_cells:
#pokemons = [p for p in cell.wild_pokemons] + [p for p in cell.catchable_pokemons]
pokemons = [p for p in cell.wild_pokemons]
# listPokemons += pokemons
for pokemon in pokemons:
listPokemons.append(pokemon)
# Normalize the ID from different protos
pokemonId = getattr(pokemon, "pokemon_id", None)
if not pokemonId:
pokemonId = pokemon.pokemon_data.pokemon_id
# Find distance to pokemon
dist = Location.getDistance(
latitude,
longitude,
pokemon.latitude,
pokemon.longitude
)
logging.info("%s, %f meters away" % (
pokedex[pokemonId],
dist
))
rarity = pokedex.getRarityById(pokemonId)
# Greedy for rarest
if rarity > best:
pokemonBest = pokemon
best = rarity
closest = dist
# Greedy for closest of same rarity
elif rarity == best and dist < closest:
pokemonBest = pokemon
closest = dist
logging.info('----------- SIZE TOTAL: ' + str(len(listPokemons)))
# return pokemonBest
return listPokemons
示例14: sortCloseForts
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def sortCloseForts(session):
# Sort nearest forts (pokestop)
cells = session.getMapObjects()
latitude, longitude, _ = session.getCoordinates()
ordered_forts = []
for cell in cells.map_cells:
for fort in cell.forts:
dist = Location.getDistance(
latitude,
longitude,
fort.latitude,
fort.longitude
)
if fort.type == 1:
ordered_forts.append({'distance': dist, 'fort': fort})
ordered_forts = sorted(ordered_forts, key=lambda k: k['distance'])
return [instance['fort'] for instance in ordered_forts]
示例15: sortCloseForts
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getDistance [as 别名]
def sortCloseForts(session):
# Sort nearest forts (pokestop)
logging.debug("Sorting Closest Poke Stop in %im", config.radius)
latitude, longitude, _ = session.getCoordinates()
ordered_forts = []
for cell in session.getMapCells(radius = config.radius):
for fort in cell.forts:
dist = Location.getDistance(
latitude,
longitude,
fort.latitude,
fort.longitude
)
if fort.type == 1 and fort.cooldown_complete_timestamp_ms == 0:
ordered_forts.append({'distance': dist, 'fort': fort})
ordered_forts = sorted(ordered_forts, key=lambda k: k['distance'])
return [instance['fort'] for instance in ordered_forts]